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
- #close ⇒ Object
- #initialize_command(*command) ⇒ Object
- #refresh ⇒ Object
-
#set_process_manager_callbacks(pm) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Instance Method Details
#close ⇒ Object
41 42 43 |
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 41 def close @process_manager&.close end |
#initialize_command(*command) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 14 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 |
#refresh ⇒ Object
36 37 38 39 |
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 36 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
rubocop:disable Naming/MethodParameterName
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/smart_proxy_dynflow/runner/process_manager_command.rb', line 25 def set_process_manager_callbacks(pm) # rubocop:disable Naming/MethodParameterName pm.on_stdout do |data| publish_data(data, 'stdout') '' end pm.on_stderr do |data| publish_data(data, 'stderr') '' end end |