3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/truth/daemon.rb', line 3
def self.run(config = Config.new)
client = Client.new(config)
p "starting truth-client daemon with configs path #{config.config_folder}"
EM.run do
subscriber = config.redis_client
redis = EM::Hiredis::Client.connect
subscriber.subscribe('server.')
msg_pattern = "truth-req.#{config.hostname}.*"
all_msg_pattern = "truth-req.all.*"
subscriber.psubscribe(msg_pattern)
subscriber.psubscribe(all_msg_pattern)
puts "subscribing to patterns #{msg_pattern} and #{all_msg_pattern}"
subscriber.on(:message) do |channel, message|
p [:message, channel, message]
end
subscriber.on(:pmessage) do |key, channel, message|
p [:pmessage, key, channel, message]
res = client.execute_command(channel, message)
redis.publish "truth-res.#{config.hostname}.response", YAML.dump(res)
end
end
end
|