Skip to content

Commit 4d82a48

Browse files
committed
Revert "Changed routing scheme."
This reverts commit b8e0961.
1 parent ac6628f commit 4d82a48

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

bin/smartguard

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def start_application(application, opts, &block)
3232

3333
Smartguard.shutting_down = true
3434
Smartguard::Logging.logger.info "Stopping services"
35-
application.stop
35+
application.stop_services
3636
end
3737

3838
rescue => e

bin/smartguardctl

+10-9
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ EventMachine.run do
8282
guard_status = amqp_channel.topic "smartguard.events", auto_delete: true
8383

8484
status_queue = amqp_channel.queue '', exclusive: true
85+
status_queue.bind guard_status, routing_key: 'command.*'
8586

8687
cmd, complete = CommandHandler.send(cmd)
87-
id = "ctl-#{Process.pid}"
88-
89-
status_queue.bind guard_status, routing_key: "command.#{id}.*"
88+
id = Process.pid
9089

9190
timer = EventMachine.add_timer(1) do
9291
warn "Smartguard is not responding"
@@ -97,15 +96,17 @@ EventMachine.run do
9796
status_queue.subscribe do |header, message|
9897
body = JSON.load(message)
9998

100-
prefix, msg_id, event = header.routing_key.split(".")
101-
if msg_id == id
102-
case event
103-
when "started"
99+
case header.routing_key
100+
when "command.started"
101+
id, = body
102+
if id == id
104103
warn "Executing command"
105104
EventMachine.cancel_timer timer
105+
end
106106

107-
when "finished"
108-
result, error = body
107+
when "command.finished"
108+
id, result, error = body
109+
if id == id
109110
if !error.nil?
110111
warn "Command failed: #{error}"
111112
elsif !complete.nil?

lib/smartguard/application.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def command(header, data)
4040
data = JSON.load data
4141

4242
operation = ->() do
43-
post_event "command.#{data["id"]}.started"
43+
post_event 'command.started', data["id"]
4444

4545
begin
4646
dispatch_command *data["command"]
@@ -51,9 +51,9 @@ def command(header, data)
5151

5252
callback = ->(result) do
5353
if result.respond_to? :exception
54-
post_event "command.#{data["id"]}.finished", nil, result.to_s
54+
post_event 'command.finished', data["id"], nil, result.to_s
5555
else
56-
post_event "command.#{data["id"]}.finished", result
56+
post_event 'command.finished', data["id"], result
5757
end
5858
end
5959

0 commit comments

Comments
 (0)