Class: ForemanInventoryUpload::Async::ShellProcess

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
AsyncHelpers, ForemanRhCloud::Async::ExponentialBackoff
Defined in:
lib/foreman_inventory_upload/async/shell_process.rb

Direct Known Subclasses

GenerateReportJob, UploadReportJob

Instance Method Summary collapse

Methods included from ForemanRhCloud::Async::ExponentialBackoff

#attempts_before_next_interval, #done!, #done?, #invoke_external_task, #poll_external_task, #poll_intervals

Methods included from AsyncHelpers

#hash_to_s

Instance Method Details

#clear_task_output(label) ⇒ Object



57
58
59
60
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 57

def clear_task_output(label)
  TaskOutputLine.where(label: label).delete_all
  TaskOutputStatus.where(label: label).delete_all
end

#commandObject



35
36
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 35

def command
end

#envObject



45
46
47
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 45

def env
  {}
end

#loggerObject



49
50
51
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 49

def logger
  Foreman::Logging.logger('background')
end

#plan(instance_label, more_inputs = {}) ⇒ Object



9
10
11
12
13
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 9

def plan(instance_label, more_inputs = {})
  clear_task_output(instance_label)
  inputs = more_inputs.merge(instance_label: instance_label)
  plan_self(inputs)
end

#progress_outputObject



38
39
40
41
42
43
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 38

def progress_output
  progress_output = ProgressOutput.register(instance_label)
  yield(progress_output)
ensure
  progress_output.close
end

#rescue_strategy_for_selfObject



53
54
55
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 53

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Fail
end

#try_executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/foreman_inventory_upload/async/shell_process.rb', line 15

def try_execute
  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}")

  assert_task_status(ProgressOutput.get(instance_label).status)
  done!
end