Class: Proxy::Dynflow::Action::Runner

Inherits:
Shareable
  • Object
show all
Includes:
Dynflow::Action::Cancellable, WithExternalPolling
Defined in:
lib/smart_proxy_dynflow/action/runner.rb

Direct Known Subclasses

BatchRunner, OutputCollector

Constant Summary

Constants included from WithExternalPolling

WithExternalPolling::Poll

Instance Method Summary collapse

Methods inherited from Shareable

#plan

Instance Method Details

#failed_run?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 88

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

#finalizeObject



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

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



64
65
66
67
68
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 64

def finish_run(update)
  output[:exit_status] = update.exit_status
  output[:result] = output_result
  drop_output_chunks!
end

#init_runObject



49
50
51
52
53
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 49

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

#initiate_runnerObject

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 45

def initiate_runner
  raise NotImplementedError
end

#kill_runObject



59
60
61
62
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 59

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

#output_resultObject



92
93
94
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 92

def output_result
  (stored_output_chunks + (@pending_output_chunks || [])).map { |c| c[:chunk] }.reduce([], &:concat)
end

#pollObject



84
85
86
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 84

def poll
  runner_dispatcher.refresh_output(output[:runner_id])
end

#process_external_event(event) ⇒ Object



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

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

#process_update(update) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 75

def process_update(update)
  output_chunk(update.continuous_output.raw_outputs) unless update.continuous_output.raw_outputs.empty?
  if update.exit_status
    finish_run(update)
  else
    suspend
  end
end

#rescue_strategy_for_selfObject



41
42
43
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 41

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

#run(event = nil) ⇒ Object



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

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

#runner_dispatcherObject



55
56
57
# File 'lib/smart_proxy_dynflow/action/runner.rb', line 55

def runner_dispatcher
  Proxy::Dynflow::Runner::Dispatcher.instance
end