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

#closeObject



38
39
40
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 38

def close
  close_io
end

#initialize_command(*command) ⇒ Object



17
18
19
20
21
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 17

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

#refreshObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/smart_proxy_dynflow/runner/command.rb', line 23

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