Class: RuoteNATS::ReplyReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote-nats/reply_receiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(engine) ⇒ ReplyReceiver

Returns a new instance of ReplyReceiver.

Parameters:

  • engine (Ruote::Engine)


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.

Parameters:

  • queue (String)

    name



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 |message, reply|
    unpacked = MessagePack.unpack(message)
    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