Class: ForemanTasksCore::Runner::Dispatcher
- Inherits:
-
Object
- Object
- ForemanTasksCore::Runner::Dispatcher
- Defined in:
- lib/foreman_tasks_core/runner/dispatcher.rb
Defined Under Namespace
Classes: RunnerActor
Class Method Summary collapse
Instance Method Summary collapse
- #finish(runner_id) ⇒ Object
- #handle_command_exception(*args) ⇒ Object
-
#initialize(clock, logger) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #kill(runner_id) ⇒ Object
- #start(suspended_action, runner) ⇒ Object
- #synchronize(&block) ⇒ Object
Constructor Details
#initialize(clock, logger) ⇒ Dispatcher
Returns a new instance of Dispatcher.
81 82 83 84 85 86 87 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 81 def initialize(clock, logger) @mutex = Mutex.new @clock = clock @logger = logger @runner_actors = {} @runner_suspended_actions = {} end |
Class Method Details
.instance ⇒ Object
4 5 6 7 8 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 4 def self.instance return @instance if @instance @instance = new(ForemanTasksCore.dynflow_world.clock, ForemanTasksCore.dynflow_world.logger) end |
Instance Method Details
#finish(runner_id) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 121 def finish(runner_id) synchronize do begin _finish(runner_id) rescue => exception _handle_command_exception(runner_id, exception, false) end end end |
#handle_command_exception(*args) ⇒ Object
131 132 133 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 131 def handle_command_exception(*args) synchronize { _handle_command_exception(*args) } end |
#kill(runner_id) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 110 def kill(runner_id) synchronize do begin runner_actor = @runner_actors[runner_id] runner_actor.tell(:kill) if runner_actor rescue => exception _handle_command_exception(runner_id, exception, false) end end end |
#start(suspended_action, runner) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 93 def start(suspended_action, runner) synchronize do begin raise "Actor with runner id #{runner.id} already exists" if @runner_actors[runner.id] runner.logger = @logger runner_actor = RunnerActor.spawn("runner-actor-#{runner.id}", self, suspended_action, runner, @clock, @logger) @runner_actors[runner.id] = runner_actor @runner_suspended_actions[runner.id] = suspended_action runner_actor.tell(:start_runner) return runner.id rescue => exception _handle_command_exception(runner.id, exception) return nil end end end |
#synchronize(&block) ⇒ Object
89 90 91 |
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 89 def synchronize(&block) @mutex.synchronize(&block) end |