2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-08 05:03:45 -06:00
|
|
|
class MessageBusDiags
|
|
|
|
@host_info = {}
|
|
|
|
|
|
|
|
def self.my_id
|
2020-02-17 22:11:30 -06:00
|
|
|
@my_id ||= "#{Discourse.os_hostname}-#{Process.pid}"
|
2013-02-08 05:03:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.seen_host(name)
|
|
|
|
@host_info[name] = DateTime.now
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.establish_peer_names
|
2017-07-27 20:20:09 -05:00
|
|
|
MessageBus.publish "/server-name", channel: "/server-name-reply/#{my_id}"
|
2013-02-08 05:03:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.seen_hosts
|
|
|
|
@host_info
|
|
|
|
end
|
2013-02-25 10:42:20 -06:00
|
|
|
|
2013-02-08 05:03:45 -06:00
|
|
|
unless @subscribed
|
2015-05-03 21:21:00 -05:00
|
|
|
MessageBus.subscribe "/server-name-reply/#{my_id}" do |msg|
|
2013-02-08 05:03:45 -06:00
|
|
|
MessageBusDiags.seen_host(msg.data)
|
|
|
|
end
|
|
|
|
|
2015-05-03 21:21:00 -05:00
|
|
|
MessageBus.subscribe "/server-name" do |msg|
|
|
|
|
MessageBus.publish msg.data["channel"], MessageBusDiags.my_id
|
2013-02-08 05:03:45 -06:00
|
|
|
end
|
|
|
|
@subscribed = true
|
|
|
|
end
|
|
|
|
end
|