Class: Dynflow::Executors::Abstract::Core

Inherits:
Actor
  • Object
show all
Defined in:
lib/dynflow/executors/abstract/core.rb

Direct Known Subclasses

Parallel::Core, Sidekiq::Core

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Actor

#behaviour_definition, #terminating?

Methods included from Actor::LogWithFullBacktrace

#log

Constructor Details

#initialize(world, heartbeat_interval, queues_options) ⇒ Core

Returns a new instance of Core.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dynflow/executors/abstract/core.rb', line 8

def initialize(world, heartbeat_interval, queues_options)
  @logger         = world.logger
  @world          = Type! world, World
  @pools          = {}
  @terminated     = nil
  @director       = Director.new(@world)
  @heartbeat_interval = heartbeat_interval
  @queues_options = queues_options

  schedule_heartbeat
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/dynflow/executors/abstract/core.rb', line 6

def logger
  @logger
end

Instance Method Details

#dead_letter_routingObject



79
80
81
# File 'lib/dynflow/executors/abstract/core.rb', line 79

def dead_letter_routing
  @world.dead_letter_handler
end

#execution_status(execution_plan_id = nil) ⇒ Object



83
84
85
# File 'lib/dynflow/executors/abstract/core.rb', line 83

def execution_status(execution_plan_id = nil)
  {}
end

#finish_terminationObject



73
74
75
76
77
# File 'lib/dynflow/executors/abstract/core.rb', line 73

def finish_termination
  @director.terminate
  logger.info '... Dynflow core terminated.'
  super()
end

#handle_event(event) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/dynflow/executors/abstract/core.rb', line 29

def handle_event(event)
  Type! event, Director::Event
  if terminating?
    raise Dynflow::Error,
          "cannot accept event: #{event} core is terminating"
  end
  handle_work(@director.handle_event(event))
end

#handle_execution(execution_plan_id, finished) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/dynflow/executors/abstract/core.rb', line 20

def handle_execution(execution_plan_id, finished)
  if terminating?
    raise Dynflow::Error,
          "cannot accept execution_plan_id:#{execution_plan_id} core is terminating"
  end

  handle_work(@director.start_execution(execution_plan_id, finished))
end

#handle_persistence_error(error, work = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/dynflow/executors/abstract/core.rb', line 58

def handle_persistence_error(error, work = nil)
  logger.error "PersistenceError in executor"
  logger.error error
  @director.work_failed(work) if work
  if error.is_a? Errors::FatalPersistenceError
    logger.fatal "Terminating"
    @world.terminate
  end
end

#handle_planning(execution_plan_id) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/dynflow/executors/abstract/core.rb', line 38

def handle_planning(execution_plan_id)
  if terminating?
    raise Dynflow::Error,
          "cannot accept event: #{event} core is terminating"
  end

  handle_work(@director.handle_planning(execution_plan_id))
end

#heartbeatObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/dynflow/executors/abstract/core.rb', line 87

def heartbeat
  @logger.debug('Executor heartbeat')
  record = @world.coordinator.find_records(:id => @world.id,
                                           :class => ['Dynflow::Coordinator::ExecutorWorld', 'Dynflow::Coordinator::ClientWorld']).first
  unless record
    logger.error(%{Executor's world record for #{@world.id} missing: terminating})
    @world.terminate
    return
  end

  record.data[:meta].update(:last_seen => Dynflow::Dispatcher::ClientDispatcher::PingCache.format_time)
  @world.coordinator.update_record(record)
  schedule_heartbeat
end

#plan_events(delayed_events) ⇒ Object



47
48
49
50
51
# File 'lib/dynflow/executors/abstract/core.rb', line 47

def plan_events(delayed_events)
  delayed_events.each do |event|
    @world.plan_event(event.execution_plan_id, event.step_id, event.event, event.time, optional: event.optional)
  end
end

#start_termination(*args) ⇒ Object



68
69
70
71
# File 'lib/dynflow/executors/abstract/core.rb', line 68

def start_termination(*args)
  logger.info 'shutting down Core ...'
  super
end

#work_finished(work, delayed_events = nil) ⇒ Object



53
54
55
56
# File 'lib/dynflow/executors/abstract/core.rb', line 53

def work_finished(work, delayed_events = nil)
  handle_work(@director.work_finished(work))
  plan_events(delayed_events) if delayed_events
end