class Dynflow::Executors::Parallel::ExecutionPlanManager

Attributes

execution_plan[R]
future[R]

Public Class Methods

new(world, execution_plan, future) click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 10
def initialize(world, execution_plan, future)
  @world                 = Type! world, World
  @execution_plan        = Type! execution_plan, ExecutionPlan
  @future                = Type! future, Concurrent::Edge::Future
  @running_steps_manager = RunningStepsManager.new(world)

  unless [:planned, :paused].include? execution_plan.state
    raise "execution_plan is not in pending or paused state, it's #{execution_plan.state}"
  end
  execution_plan.execution_history.add('start execution', @world.id)
  execution_plan.update_state(:running)
end

Public Instance Methods

done?() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 71
def done?
  (!@run_manager || @run_manager.done?) && (!@finalize_manager || @finalize_manager.done?)
end
event(event) click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 65
def event(event)
  Type! event, Parallel::Event
  raise unless event.execution_plan_id == @execution_plan.id
  @running_steps_manager.event(event)
end
prepare_next_step(step) click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 28
def prepare_next_step(step)
  Work::Step[step, execution_plan.id].tap do |work|
    @running_steps_manager.add(step, work)
  end
end
start() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 23
def start
  raise "The future was already set" if @future.completed?
  start_run or start_finalize or finish
end
terminate() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 75
def terminate
  @running_steps_manager.terminate
end
what_is_next(work) click to toggle source

@return [Array<Work>] of Work items to continue with

# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 35
def what_is_next(work)
  Type! work, Work

  compute_next_from_step =-> step do
    raise unless @run_manager
    raise if @run_manager.done?

    next_steps = @run_manager.what_is_next(step)
    if @run_manager.done?
      start_finalize or finish
    else
      next_steps.map { |s| prepare_next_step(s) }
    end
  end

  match(work,
        (on Work::Step.(step: ~any) | Work::Event.(step: ~any) do |step|
           execution_plan.steps[step.id] = step
           suspended, work = @running_steps_manager.done(step)
           unless suspended
             work = compute_next_from_step.call step
           end
           work
         end),
        (on Work::Finalize do
           raise unless @finalize_manager
           finish
         end))
end

Private Instance Methods

finish() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 102
def finish
  execution_plan.execution_history.add('finish execution', @world.id)
  @execution_plan.update_state(execution_plan.error? ? :paused : :stopped)
  return no_work
end
no_work() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 81
def no_work
  raise "No work but not done" unless done?
  []
end
start_finalize() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 94
def start_finalize
  unless execution_plan.finalize_flow.empty?
    raise 'finalize phase already started' if @finalize_manager
    @finalize_manager = SequentialManager.new(@world, execution_plan)
    Work::Finalize[@finalize_manager, execution_plan.id]
  end
end
start_run() click to toggle source
# File lib/dynflow/executors/parallel/execution_plan_manager.rb, line 86
def start_run
  unless execution_plan.run_flow.empty?
    raise 'run phase already started' if @run_manager
    @run_manager = FlowManager.new(execution_plan, execution_plan.run_flow)
    @run_manager.start.map { |s| prepare_next_step(s) }.tap { |a| raise if a.empty? }
  end
end