Class: ForemanTasksCore::Runner::CommandRunner

Inherits:
Base
  • Object
show all
Defined in:
lib/foreman_tasks_core/runner/command_runner.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #logger

Instance Method Summary collapse

Methods inherited from Base

#initialize, #kill, #publish_data, #publish_exception, #publish_exit_status, #run_refresh, #start, #timeout, #timeout_interval

Constructor Details

This class inherits a constructor from ForemanTasksCore::Runner::Base

Instance Method Details

#closeObject



26
27
28
# File 'lib/foreman_tasks_core/runner/command_runner.rb', line 26

def close
  close_io
end

#initialize_command(*command) ⇒ Object



7
8
9
# File 'lib/foreman_tasks_core/runner/command_runner.rb', line 7

def initialize_command(*command)
  @command_out, @command_in, @command_pid = PTY.spawn(*command)
end

#refreshObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/foreman_tasks_core/runner/command_runner.rb', line 11

def refresh
  return if @command_out.nil?
  ready_outputs, * = IO.select([@command_out], nil, nil, 0.1)
  if ready_outputs
    if @command_out.nread > 0
      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