Class: ForemanTasksCore::Runner::Dispatcher::RunnerActor

Inherits:
Dynflow::Actor
  • Object
show all
Defined in:
lib/foreman_tasks_core/runner/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher, suspended_action, runner, clock, logger, options = {}) ⇒ RunnerActor

Returns a new instance of RunnerActor.



11
12
13
14
15
16
17
18
19
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 11

def initialize(dispatcher, suspended_action, runner, clock, logger, options = {})
  @dispatcher = dispatcher
  @clock = clock
  @logger = logger
  @suspended_action = suspended_action
  @runner = runner
  @finishing = false
  @refresh_interval = options[:refresh_interval] || 1
end

Instance Method Details

#finishObject



53
54
55
56
57
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 53

def finish
  @logger.debug("finish runner #{@runner.id}")
  @finishing = true
  @dispatcher.finish(@runner.id)
end

#killObject



46
47
48
49
50
51
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 46

def kill
  @logger.debug("kill runner #{@runner.id}")
  @runner.kill
rescue => e
  handle_exception(e, false)
end

#on_envelope(*args) ⇒ Object



21
22
23
24
25
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 21

def on_envelope(*args)
  super
rescue => e
  handle_exception(e)
end

#refresh_runnerObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 35

def refresh_runner
  @logger.debug("refresh runner #{@runner.id}")
  if (update = @runner.run_refresh)
    @suspended_action << update
    finish if update.exit_status
  end
ensure
  @refresh_planned = false
  plan_next_refresh
end

#start_runnerObject



27
28
29
30
31
32
33
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 27

def start_runner
  @logger.debug("start runner #{@runner.id}")
  @runner.start
  refresh_runner
ensure
  plan_next_refresh
end

#start_termination(*args) ⇒ Object



59
60
61
62
63
64
# File 'lib/foreman_tasks_core/runner/dispatcher.rb', line 59

def start_termination(*args)
  @logger.debug("terminate #{@runner.id}")
  super
  @runner.close
  finish_termination
end