Class: Cadence::Workflow::StateManager
- Inherits:
-
Object
- Object
- Cadence::Workflow::StateManager
show all
- Defined in:
- lib/cadence/workflow/state_manager.rb
Defined Under Namespace
Classes: UnsupportedEvent, UnsupportedMarkerType
Constant Summary
collapse
- SIDE_EFFECT_MARKER =
'SIDE_EFFECT'.freeze
- RELEASE_MARKER =
'RELEASE'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dispatcher) ⇒ StateManager
Returns a new instance of StateManager.
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cadence/workflow/state_manager.rb', line 19
def initialize(dispatcher)
@dispatcher = dispatcher
@decisions = []
@marker_ids = Set.new
@releases = {}
@side_effects = []
@decision_tracker = Hash.new { |hash, key| hash[key] = DecisionStateMachine.new }
@last_event_id = 0
@local_time = nil
@replay = false
end
|
Instance Attribute Details
#decisions ⇒ Object
Returns the value of attribute decisions.
17
18
19
|
# File 'lib/cadence/workflow/state_manager.rb', line 17
def decisions
@decisions
end
|
#local_time ⇒ Object
Returns the value of attribute local_time.
17
18
19
|
# File 'lib/cadence/workflow/state_manager.rb', line 17
def local_time
@local_time
end
|
Instance Method Details
#apply(history_window) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/cadence/workflow/state_manager.rb', line 71
def apply(history_window)
@replay = history_window.replay?
@local_time = history_window.local_time
@last_event_id = history_window.last_event_id
history_window.markers.each do |event|
apply_event(event)
end
history_window.events.each do |event|
apply_event(event)
end
end
|
#next_side_effect ⇒ Object
67
68
69
|
# File 'lib/cadence/workflow/state_manager.rb', line 67
def next_side_effect
side_effects.shift
end
|
#release?(release_name) ⇒ Boolean
61
62
63
64
65
|
# File 'lib/cadence/workflow/state_manager.rb', line 61
def release?(release_name)
track_release(release_name) unless releases.key?(release_name)
releases[release_name]
end
|
#replay? ⇒ Boolean
31
32
33
|
# File 'lib/cadence/workflow/state_manager.rb', line 31
def replay?
@replay
end
|
#schedule(decision) ⇒ Object
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
|
# File 'lib/cadence/workflow/state_manager.rb', line 35
def schedule(decision)
decision_id = next_event_id
while marker_ids.include?(decision_id) do
decision_id = next_event_id
end
cancelation_id =
case decision
when Decision::ScheduleActivity
decision.activity_id ||= decision_id
when Decision::StartChildWorkflow
decision.workflow_id ||= decision_id
when Decision::StartTimer
decision.timer_id ||= decision_id
end
state_machine = decision_tracker[decision_id]
state_machine.requested if state_machine.state == DecisionStateMachine::NEW_STATE
decisions << [decision_id, decision]
return [event_target_from(decision_id, decision), cancelation_id]
end
|