-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathfuture_execution.rb
executable file
·71 lines (57 loc) · 2.02 KB
/
future_execution.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'example_helper'
class CustomPassedObject
attr_reader :id, :name
def initialize(id, name)
@id = id
@name = name
end
end
class CustomPassedObjectSerializer < ::Dynflow::Serializers::Abstract
def serialize(arg)
# Serialized output can be anything that is representable as JSON: Array, Hash...
{ :id => arg.id, :name => arg.name }
end
def deserialize(arg)
# Deserialized output must be an Array
CustomPassedObject.new(arg[:id], arg[:name])
end
end
class DelayedAction < Dynflow::Action
def delay(delay_options, *args)
CustomPassedObjectSerializer.new(args)
end
def plan(passed_object)
plan_self :object_id => passed_object.id, :object_name => passed_object.name
end
def run
end
end
if $0 == __FILE__
ExampleHelper.world.action_logger.level = 1
ExampleHelper.world.logger.level = 0
past = Time.now - 200
near_future = Time.now + 29
future = Time.now + 180
object = CustomPassedObject.new(1, 'CPS')
past_plan = ExampleHelper.world.delay(DelayedAction, { :start_at => past, :start_before => past }, object)
near_future_plan = ExampleHelper.world.delay(DelayedAction, { :start_at => near_future, :start_before => future }, object)
future_plan = ExampleHelper.world.delay(DelayedAction, { :start_at => future }, object)
puts <<-MSG.gsub(/^.*\|/, '')
|
| Future Execution Example
| ========================
|
| This example shows the future execution functionality of Dynflow, which allows to plan actions to be executed at set time.
|
| Execution plans:
| #{past_plan.id} is "delayed" to execute before #{past} and should timeout on the first run of the scheduler.
| #{near_future_plan.id} is delayed to execute at #{near_future} and should run successfully.
| #{future_plan.id} is delayed to execute at #{future} and should run successfully.
|
| Visit #{ExampleHelper::DYNFLOW_URL} to see their status.
|
MSG
ExampleHelper.run_web_console
end