Class: MessageBus::Diagnostics

Inherits:
Object
  • Object
show all
Defined in:
lib/message_bus/diagnostics.rb

Overview

MessageBus diagnostics are used for troubleshooting the bus and optimising its configuration

See Also:

Class Method Summary collapse

Class Method Details

.enable(bus = MessageBus) ⇒ void

This method returns an undefined value.

Enables diagnostics functionality

Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/message_bus/diagnostics.rb', line 9

def enable(bus = MessageBus)
  full_path = full_process_path
  start_time = Time.now.to_f
  hostname = get_hostname

  # it may make sense to add a channel per machine/host to streamline
  #  process to process comms
  bus.subscribe('/_diagnostics/hup') do |msg|
    if Process.pid == msg.data["pid"] && hostname == msg.data["hostname"]
      sleep 4
      Process.kill("HUP", $$)
    end
  end

  bus.subscribe('/_diagnostics/discover') do |msg|
    bus.on_connect.call msg.site_id if bus.on_connect
    bus.publish '/_diagnostics/process-discovery', {
      pid: Process.pid,
      process_name: $0,
      full_path: full_path,
      uptime: (Time.now.to_f - start_time).to_i,
      hostname: hostname
    }, user_ids: [msg.data["user_id"]]
    bus.on_disconnect.call msg.site_id if bus.on_disconnect
  end
end