class ForemanInventoryUpload::Async::ShellProcess

Public Instance Methods

command() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 30
def command
end
env() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 40
def env
  {}
end
logger() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 44
def logger
  Foreman::Logging.logger('background')
end
plan(instance_label, more_inputs = {}) click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 8
def plan(instance_label, more_inputs = {})
  inputs = more_inputs.merge(instance_label: instance_label)
  plan_self(inputs)
end
progress_output() { |progress_output| ... } click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 33
def progress_output
  progress_output = ProgressOutput.register(instance_label)
  yield(progress_output)
ensure
  progress_output.close
end
rescue_strategy_for_self() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 48
def rescue_strategy_for_self
  Dynflow::Action::Rescue::Fail
end
run() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 13
def run
  klass_name = self.class.name
  logger.debug("Starting #{klass_name} with label #{instance_label}")
  progress_output do |progress_output|
    Open3.popen2e(hash_to_s(env), *preprocess_command(command)) do |_stdin, stdout_stderr, wait_thread|
      progress_output.status = "Running in pid #{wait_thread.pid}"

      stdout_stderr.each do |out_line|
        progress_output.write_line(out_line)
      end

      progress_output.status = wait_thread.value.to_s
    end
  end
  logger.debug("Finished job #{klass_name} with label #{instance_label}")
end

Private Instance Methods

instance_label() click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 58
def instance_label
  input[:instance_label]
end
preprocess_command(command) click to toggle source
# File lib/foreman_inventory_upload/async/shell_process.rb, line 54
def preprocess_command(command)
  command.kind_of?(Array) ? command : [command]
end