2013-02-08 19:03:45 +08:00
|
|
|
class MessageBusDiags
|
|
|
|
|
|
|
|
@host_info = {}
|
|
|
|
|
|
|
|
def self.my_id
|
|
|
|
@my_id ||= "#{`hostname`}-#{Process.pid}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.seen_host(name)
|
|
|
|
@host_info[name] = DateTime.now
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.establish_peer_names
|
2015-04-25 01:10:43 +08:00
|
|
|
DiscourseBus.publish "/server-name", {channel: "/server-name-reply/#{my_id}"}
|
2013-02-08 19:03:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.seen_hosts
|
|
|
|
@host_info
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-08 19:03:45 +08:00
|
|
|
unless @subscribed
|
|
|
|
|
2015-04-25 01:10:43 +08:00
|
|
|
DiscourseBus.subscribe "/server-name-reply/#{my_id}" do |msg|
|
2013-02-08 19:03:45 +08:00
|
|
|
MessageBusDiags.seen_host(msg.data)
|
|
|
|
end
|
|
|
|
|
2015-04-25 01:10:43 +08:00
|
|
|
DiscourseBus.subscribe "/server-name" do |msg|
|
|
|
|
DiscourseBus.publish msg.data["channel"], MessageBusDiags.my_id
|
2013-02-08 19:03:45 +08:00
|
|
|
end
|
|
|
|
@subscribed = true
|
|
|
|
end
|
|
|
|
end
|