Class: ForemanTasksCore::Runner::Action

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

Instance Method Summary collapse

Methods inherited from ShareableAction

#plan

Instance Method Details

#failed_run?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/foreman_tasks_core/runner/action.rb', line 64

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

#finalizeObject



23
24
25
26
# File 'lib/foreman_tasks_core/runner/action.rb', line 23

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

#finish_run(update) ⇒ Object



51
52
53
# File 'lib/foreman_tasks_core/runner/action.rb', line 51

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

#init_runObject



36
37
38
39
40
# File 'lib/foreman_tasks_core/runner/action.rb', line 36

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

#initiate_runnerObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/foreman_tasks_core/runner/action.rb', line 32

def initiate_runner
  raise NotImplementedError
end

#kill_runObject



46
47
48
49
# File 'lib/foreman_tasks_core/runner/action.rb', line 46

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

#process_update(update) ⇒ Object



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

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



28
29
30
# File 'lib/foreman_tasks_core/runner/action.rb', line 28

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
# 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 ::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



42
43
44
# File 'lib/foreman_tasks_core/runner/action.rb', line 42

def runner_dispatcher
  Runner::Dispatcher.instance
end