Class: Dynflow::DelayedPlan

Inherits:
Serializable show all
Includes:
Algebrick::TypeCheck
Defined in:
lib/dynflow/delayed_plan.rb

Constant Summary

Constants inherited from Serializable

Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Serializable

constantize, from_hash

Constructor Details

#initialize(world, execution_plan_uuid, start_at, start_before, args_serializer, frozen) ⇒ DelayedPlan

Returns a new instance of DelayedPlan.



10
11
12
13
14
15
16
17
# File 'lib/dynflow/delayed_plan.rb', line 10

def initialize(world, execution_plan_uuid, start_at, start_before, args_serializer, frozen)
  @world               = Type! world, World
  @execution_plan_uuid = Type! execution_plan_uuid, String
  @start_at            = Type! start_at, Time, NilClass
  @start_before        = Type! start_before, Time, NilClass
  @args_serializer     = Type! args_serializer, Serializers::Abstract
  @frozen              = Type! frozen, Algebrick::Types::Boolean
end

Instance Attribute Details

#execution_plan_uuidObject (readonly)

Returns the value of attribute execution_plan_uuid.



7
8
9
# File 'lib/dynflow/delayed_plan.rb', line 7

def execution_plan_uuid
  @execution_plan_uuid
end

#frozenObject

Returns the value of attribute frozen.



8
9
10
# File 'lib/dynflow/delayed_plan.rb', line 8

def frozen
  @frozen
end

#start_atObject

Returns the value of attribute start_at.



8
9
10
# File 'lib/dynflow/delayed_plan.rb', line 8

def start_at
  @start_at
end

#start_beforeObject (readonly)

Returns the value of attribute start_before.



7
8
9
# File 'lib/dynflow/delayed_plan.rb', line 7

def start_before
  @start_before
end

Class Method Details

.new_from_hash(world, hash, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dynflow/delayed_plan.rb', line 78

def self.new_from_hash(world, hash, *args)
  serializer = Utils.constantize(hash[:args_serializer]).new(nil, hash[:serialized_args])
  self.new(world,
    hash[:execution_plan_uuid],
    string_to_time(hash[:start_at]),
    string_to_time(hash[:start_before]),
    serializer,
    hash[:frozen] || false)
rescue NameError => e
  error(e.message)
end

Instance Method Details

#argsArray

Retrieves arguments from the serializer

Returns:

  • (Array)

    array of the original arguments



72
73
74
75
# File 'lib/dynflow/delayed_plan.rb', line 72

def args
  @args_serializer.perform_deserialization! if @args_serializer.args.nil?
  @args_serializer.args
end

#cancelObject



47
48
49
50
51
52
53
# File 'lib/dynflow/delayed_plan.rb', line 47

def cancel
  execution_plan.root_plan_step.state = :cancelled
  execution_plan.root_plan_step.save
  execution_plan.update_state :stopped, history_notice: "Delayed task cancelled"
  @world.persistence.delete_delayed_plans(:execution_plan_uuid => @execution_plan_uuid)
  return true
end

#error(message, history_entry = nil) ⇒ Object



40
41
42
43
44
45
# File 'lib/dynflow/delayed_plan.rb', line 40

def error(message, history_entry = nil)
  execution_plan.root_plan_step.state = :error
  execution_plan.root_plan_step.error = ::Dynflow::ExecutionPlan::Steps::Error.new(message)
  execution_plan.root_plan_step.save
  execution_plan.update_state :stopped, history_notice: history_entry
end

#execute(future = Concurrent::Promises.resolvable_future) ⇒ Object



55
56
57
58
# File 'lib/dynflow/delayed_plan.rb', line 55

def execute(future = Concurrent::Promises.resolvable_future)
  @world.execute(@execution_plan_uuid, future)
  ::Dynflow::World::Triggered[@execution_plan_uuid, future]
end

#execution_planObject



19
20
21
# File 'lib/dynflow/delayed_plan.rb', line 19

def execution_plan
  @execution_plan ||= @world.persistence.load_execution_plan(@execution_plan_uuid)
end

#failed_dependencies(uuids) ⇒ Object



34
35
36
37
38
# File 'lib/dynflow/delayed_plan.rb', line 34

def failed_dependencies(uuids)
  bullets = uuids.map { |u| "- #{u}" }.join("\n")
  msg = "Execution plan could not be started because some of its prerequisite execution plans failed:\n#{bullets}"
  error(msg, 'failed-dependency')
end

#planObject



23
24
25
26
27
28
# File 'lib/dynflow/delayed_plan.rb', line 23

def plan
  execution_plan.root_plan_step.load_action
  execution_plan.generate_action_id
  execution_plan.generate_step_id
  execution_plan.plan(*@args_serializer.perform_deserialization!)
end

#timeoutObject



30
31
32
# File 'lib/dynflow/delayed_plan.rb', line 30

def timeout
  error("Execution plan could not be started before set time (#{@start_before})", 'timeout')
end

#to_hashObject



60
61
62
63
64
65
66
67
# File 'lib/dynflow/delayed_plan.rb', line 60

def to_hash
  recursive_to_hash :execution_plan_uuid => @execution_plan_uuid,
                    :start_at            => @start_at,
                    :start_before        => @start_before,
                    :serialized_args     => @args_serializer.serialized_args,
                    :args_serializer     => @args_serializer.class.name,
                    :frozen              => @frozen
end