Module: Proxy::Dynflow::Runner::Command
- Included in:
- CommandRunner
- Defined in:
- lib/smart_proxy_dynflow/runner/command.rb
Overview
This module expects to be included into a Runner action, where it can be used to simplify handling of long-running processes. However it tracks the running process as a group of instance variables, which has served us reasonably well in the past, but can be rather error prone.
A better alternative to this is ProcessManagerCommand. It tracks the whole execution of a process under a single instance variable and uses a more robust ProcessManager under the hood. It also maintains the same interface and can be used as a drop-in replacement.
This module is now soft-deprecated and ProcessManagerCommand should be used instead.
Instance Method Summary collapse
Instance Method Details
#close ⇒ Object
41 42 43 |
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 41 def close close_io end |
#initialize_command(*command) ⇒ Object
19 20 21 22 23 |
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 19 def initialize_command(*command) @command_out, @command_in, @command_pid = PTY.spawn(*command) rescue Errno::ENOENT => e publish_exception("Error running command '#{command.join(' ')}'", e) end |
#refresh ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 25 def refresh return if @command_out.nil? ready_outputs, * = IO.select([@command_out], nil, nil, 0.1) if ready_outputs if @command_out.nread.positive? lines = @command_out.read_nonblock(@command_out.nread) else close_io Process.wait(@command_pid) publish_exit_status($CHILD_STATUS.exitstatus) end publish_data(lines, 'stdout') if lines && !lines.empty? end end |