Class: RuoteNATS::Participant

Inherits:
Object
  • Object
show all
Includes:
Ruote::LocalParticipant
Defined in:
lib/ruote-nats/participant.rb

Overview

RuoteNATS::Participant

Constant Summary collapse

DEFALUT_TIMEOUT =
1

Instance Method Summary collapse

Instance Method Details

#cancelObject



34
35
# File 'lib/ruote-nats/participant.rb', line 34

def cancel
end

#consume(workitem) ⇒ Object

Parameters:

  • workitem (Ruote::Workitem)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruote-nats/participant.rb', line 14

def consume(workitem)
  queue_name = workitem.lookup('params.queue') || 'remote.command'
  message    = MessagePack.pack(workitem.to_h)

  sid = NATS.request(queue_name, message) do |reply|
    RuoteNATS.logger.info do
      executor = workitem.lookup('params.executor') || 'RuoteNATS::ShellExecutor'
      "(#{workitem.sid}) request: #{executor} (#{workitem.lookup('params')})"
    end
  end

  timeout = (workitem.lookup('params.timeout') || DEFALUT_TIMEOUT).to_i
  NATS.timeout(sid, timeout) do
    handle_error(workitem)
  end
rescue
  RuoteNATS.logger.error($!.message)
  raise $!
end