Class: Dynflow::ExecutionPlan::Steps::PlanStep

Inherits:
Abstract show all
Defined in:
lib/dynflow/execution_plan/steps/plan_step.rb

Instance Attribute Summary collapse

Attributes inherited from Abstract

#action_class, #action_id, #ended_at, #error, #execution_plan_id, #execution_time, #id, #progress_weight, #real_time, #started_at, #state, #world

Attributes included from Stateful

#state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#action, #action_logger, #cancellable?, #default_progress_done, #mark_to_skip, #persistence, #progress_done, #save, #skippable?, states, #to_s

Methods included from Stateful

included, #set_state, #state_transitions, #states

Methods inherited from Serializable

constantize, from_hash

Constructor Details

#initialize(execution_plan_id, id, state, action_class, action_id, error, world, started_at = nil, ended_at = nil, execution_time = 0.0, real_time = 0.0, children = []) ⇒ PlanStep

Returns a new instance of PlanStep.

Parameters:

  • children (Array) (defaults to: [])

    is a private API parameter



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 7

def initialize(execution_plan_id,
    id,
    state,
    action_class,
    action_id,
    error,
    world,
    started_at = nil,
    ended_at = nil,
    execution_time = 0.0,
    real_time = 0.0,
    children = [])

  super execution_plan_id, id, state, action_class, action_id, error, world, started_at,
        ended_at, execution_time, real_time
  children.all? { |child| Type! child, Integer }
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 4

def children
  @children
end

Class Method Details

.new_from_hash(hash, execution_plan_id, world) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 63

def self.new_from_hash(hash, execution_plan_id, world)
  check_class_matching hash
  new execution_plan_id,
      hash[:id],
      hash[:state],
      Action.constantize(hash[:action_class]),
      hash[:action_id],
      hash_to_error(hash[:error]),
      world,
      string_to_time(hash[:started_at]),
      string_to_time(hash[:ended_at]),
      hash[:execution_time],
      hash[:real_time],
      hash[:children]
end

.state_transitionsObject



53
54
55
56
57
58
59
60
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 53

def self.state_transitions
  @state_transitions ||= { pending:   [:running],
                           running:   [:success, :error],
                           success:   [],
                           suspended: [],
                           skipped:   [],
                           error:     [] }
end

Instance Method Details

#execute(execution_plan, trigger, from_subscription, *args) ⇒ Action

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 39

def execute(execution_plan, trigger, from_subscription, *args)
  unless @action
    raise "The action was not initialized, you might forgot to call initialize_action method"
  end
  @action.set_plan_context(execution_plan, trigger, from_subscription)
  Type! execution_plan, ExecutionPlan
  with_meta_calculation(@action) do
    @action.execute(*args)
  end

  persistence.save_action(execution_plan_id, @action)
  return @action
end

#initialize_actionObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 79

def initialize_action
  attributes = { execution_plan_id: execution_plan_id,
                 id:                action_id,
                 step:              self,
                 plan_step_id:      self.id,
                 run_step_id:       nil,
                 finalize_step_id:  nil,
                 phase:             phase}
  @action = action_class.new(attributes, world)
  persistence.save_action(execution_plan_id, @action)
  @action
end

#phaseObject



30
31
32
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 30

def phase
  Action::Plan
end

#planned_steps(execution_plan) ⇒ Object



26
27
28
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 26

def planned_steps(execution_plan)
  @children.map { |id| execution_plan.steps.fetch(id) }
end

#to_hashObject



34
35
36
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 34

def to_hash
  super.merge recursive_to_hash(:children => children)
end