Class: RuoteNATS::ReplyReceiver
- Inherits:
-
Object
- Object
- RuoteNATS::ReplyReceiver
- Defined in:
- lib/ruote-nats/reply_receiver.rb
Instance Method Summary collapse
-
#initialize(engine) ⇒ ReplyReceiver
constructor
A new instance of ReplyReceiver.
-
#start(queue_name = 'remote.command.reply') ⇒ Object
Start to subscribe reply queue.
Constructor Details
#initialize(engine) ⇒ ReplyReceiver
Returns a new instance of ReplyReceiver.
5 6 7 |
# File 'lib/ruote-nats/reply_receiver.rb', line 5 def initialize(engine) @engine = engine end |
Instance Method Details
#start(queue_name = 'remote.command.reply') ⇒ Object
Start to subscribe reply queue.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruote-nats/reply_receiver.rb', line 12 def start(queue_name = 'remote.command.reply') NATS.subscribe(queue_name) do |, reply| unpacked = MessagePack.unpack() workitem = Ruote::Workitem.new(unpacked) RuoteNATS.logger.info do executor = workitem.lookup('params.executor') || 'RuoteNATS::ShellExecutor' result = workitem.lookup("results.#{workitem.sid}") "(#{workitem.sid}) receive reply: #{executor} #{workitem.result} (#{result})" end if workitem.result == 'success' @engine.reply_to_engine(workitem) else handle_error(workitem) end end end |