Module: Proxy::Dynflow::Runner::ProcessManagerCommand

Defined in:
lib/smart_proxy_dynflow/runner/process_manager_command.rb

Overview

A convenience module which should be included into a Runner action. It leverages ProcessManager to reliably keep track of an external process and collect its output.

The only expectation from the Runner action is to call #initialize_command somewhere and pass the command to be run to it.

Instance Method Summary collapse

Instance Method Details

#closeObject



39
40
41
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 39

def close
  @process_manager&.close
end

#initialize_command(*command) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 12

def initialize_command(*command)
  @process_manager = ProcessManager.new(command)
  set_process_manager_callbacks(@process_manager)
  @process_manager.start!
  if @process_manager.done? && @process_manager.status == 255
    exception = RuntimeError.new(@process_manager.stderr.to_s)
    exception.set_backtrace Thread.current.backtrace
    publish_exception("Error running command '#{command.join(' ')}'", exception)
  end
end

#refreshObject



34
35
36
37
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 34

def refresh
  @process_manager.process(timeout: 0.1) unless @process_manager.done?
  publish_exit_status(@process_manager.status) if @process_manager.done?
end

#set_process_manager_callbacks(pm) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 23

def set_process_manager_callbacks(pm)
  pm.on_stdout do |data|
    publish_data(data, 'stdout')
    ''
  end
  pm.on_stderr do |data|
    publish_data(data, 'stderr')
    ''
  end
end