Class: RuoteNATS::ShellExecutor

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

Instance Method Summary collapse

Instance Method Details

#execute(workitem) ⇒ Hash

Execute shell command

Parameters:

  • workitem (Ruote::Workitem)

Returns:

  • (Hash)

    the result of command execution



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruote-nats/shell_executor.rb', line 8

def execute(workitem)
  if workitem.lookup('params.command')
    out, status = invoke(workitem)

    if status.success?
      { out: out, status: status.exitstatus, finished_at: Ruote.now_to_utc_s }
    else
      raise "out: #{out}, status: #{status.exitstatus}, finished_at: #{Ruote.now_to_utc_s}"
    end
  else
    workitem.result = 'failure'

    message = 'command is not specified, check your process definition'
    RuoteNATS.logger.error do
      "(#{workitem.sid}) shell: #{message}"
    end
    raise message
  end
end