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
constantize, from_hash
Constructor Details
#initialize(world, execution_plan_uuid, start_at, start_before, args_serializer, frozen) ⇒ 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_uuid ⇒ Object
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
|
#frozen ⇒ Object
Returns the value of attribute frozen.
8
9
10
|
# File 'lib/dynflow/delayed_plan.rb', line 8
def frozen
@frozen
end
|
#start_at ⇒ Object
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_before ⇒ Object
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.
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/dynflow/delayed_plan.rb', line 72
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
#args ⇒ Array
Retrieves arguments from the serializer
66
67
68
69
|
# File 'lib/dynflow/delayed_plan.rb', line 66
def args
@args_serializer.perform_deserialization! if @args_serializer.args.nil?
@args_serializer.args
end
|
#cancel ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/dynflow/delayed_plan.rb', line 41
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
34
35
36
37
38
39
|
# File 'lib/dynflow/delayed_plan.rb', line 34
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
49
50
51
52
|
# File 'lib/dynflow/delayed_plan.rb', line 49
def execute(future = Concurrent::Promises.resolvable_future)
@world.execute(@execution_plan_uuid, future)
::Dynflow::World::Triggered[@execution_plan_uuid, future]
end
|
#execution_plan ⇒ Object
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
|
#plan ⇒ Object
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
|
#timeout ⇒ Object
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_hash ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/dynflow/delayed_plan.rb', line 54
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
|