Class: ForemanTasksCore::Runner::Action

Inherits:
ShareableAction show all
Includes:
Dynflow::Action::Cancellable
Defined in:
lib/foreman_tasks_core/runner/action.rb

Direct Known Subclasses

BatchRunnerAction, OutputCollectorAction

Instance Method Summary collapse

Methods inherited from ShareableAction

#plan

Instance Method Details

#failed_run?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/foreman_tasks_core/runner/action.rb', line 71

def failed_run?
  output[:exit_status] != 0
end

#finalizeObject



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

def finalize
  # To mark the task as a whole as failed
  error! 'Script execution failed' if on_proxy? && failed_run?
end

#finish_run(update) ⇒ Object



53
54
55
# File 'lib/foreman_tasks_core/runner/action.rb', line 53

def finish_run(update)
  output[:exit_status] = update.exit_status
end

#init_runObject



38
39
40
41
42
# File 'lib/foreman_tasks_core/runner/action.rb', line 38

def init_run
  output[:result] = []
  output[:runner_id] = runner_dispatcher.start(suspended_action, initiate_runner)
  suspend
end

#initiate_runnerObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/foreman_tasks_core/runner/action.rb', line 34

def initiate_runner
  raise NotImplementedError
end

#kill_runObject



48
49
50
51
# File 'lib/foreman_tasks_core/runner/action.rb', line 48

def kill_run
  runner_dispatcher.kill(output[:runner_id])
  suspend
end

#process_external_event(event) ⇒ Object



57
58
59
60
# File 'lib/foreman_tasks_core/runner/action.rb', line 57

def process_external_event(event)
  runner_dispatcher.external_event(output[:runner_id], event)
  suspend
end

#process_update(update) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/foreman_tasks_core/runner/action.rb', line 62

def process_update(update)
  output[:result].concat(update.continuous_output.raw_outputs)
  if update.exit_status
    finish_run(update)
  else
    suspend
  end
end

#rescue_strategy_for_selfObject



30
31
32
# File 'lib/foreman_tasks_core/runner/action.rb', line 30

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

#run(event = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/foreman_tasks_core/runner/action.rb', line 7

def run(event = nil)
  case event
  when nil
    init_run
  when Runner::Update
    process_update(event)
  when Runner::ExternalEvent
    process_external_event(event)
  when ::Dynflow::Action::Cancellable::Cancel
    kill_run
  else
    raise "Unexpected event #{event.inspect}"
  end
rescue => e
  action_logger.error(e)
  process_update(Runner::Update.encode_exception('Proxy error', e))
end

#runner_dispatcherObject



44
45
46
# File 'lib/foreman_tasks_core/runner/action.rb', line 44

def runner_dispatcher
  Runner::Dispatcher.instance
end