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

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

Constant Summary

Constants inherited from Serializable

Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Abstract

#action_class, #action_id, #delayed_events, #ended_at, #error, #execution_plan_id, #execution_time, #id, #progress_weight, #queue, #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, #with_sub_plans?

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



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

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.



6
7
8
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 6

def children
  @children
end

Class Method Details

.new_from_hash(hash, execution_plan_id, world) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 74

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



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

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

Instance Method Details

#delay(delay_options, args) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 40

def delay(delay_options, args)
  @action.execute_delay(delay_options, *args)
  persistence.save_action(execution_plan_id, @action)
  @action.serializer
ensure
  save
end

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

Returns:



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

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_action(caller_action = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 94

def initialize_action(caller_action = nil)
  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 }
  if caller_action
    if caller_action.execution_plan_id != execution_plan_id
      attributes.update(caller_execution_plan_id: caller_action.execution_plan_id)
    end
    attributes.update(caller_action_id: caller_action.id)
  end
  @action = action_class.new(attributes, world)
  persistence.save_action(execution_plan_id, @action)
  @action
end

#load_actionObject



90
91
92
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 90

def load_action
  @action = @world.persistence.load_action(self)
end

#phaseObject



32
33
34
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 32

def phase
  Action::Plan
end

#planned_steps(execution_plan) ⇒ Object



28
29
30
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 28

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

#to_hashObject



36
37
38
# File 'lib/dynflow/execution_plan/steps/plan_step.rb', line 36

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