class Temporal::Workflow::History
Constants
- COMMAND_EVENT_TYPES
Attributes
events[R]
iterator[R]
Public Class Methods
new(events)
click to toggle source
# File lib/temporal/workflow/history.rb, line 9 def initialize(events) @events = events.map { |event| History::Event.new(event) } @iterator = @events.each end
Public Instance Methods
last_completed_workflow_task()
click to toggle source
# File lib/temporal/workflow/history.rb, line 14 def last_completed_workflow_task events.select { |event| event.type == 'WORKFLOW_TASK_COMPLETED' }.last end
next_window()
click to toggle source
It is very important to replay the History
window by window in order to simulate the exact same state the workflow was in when it processed the workflow task for the first time.
A history window consists of 3 parts:
-
Events that happened since the last window (timer fired, activity completed, etc)
-
A workflow task related events (workflow task started, completed, failed, etc)
-
Commands issued by the last workflow task (^) (schedule activity, start timer, etc)
# File lib/temporal/workflow/history.rb, line 28 def next_window return unless peek_event window = History::Window.new while event = next_event window.add(event) break if event.type == 'WORKFLOW_TASK_COMPLETED' end # Find the end of the window by exhausting all the commands window.add(next_event) while command?(peek_event) window.freeze end
Private Instance Methods
command?(event)
click to toggle source
# File lib/temporal/workflow/history.rb, line 71 def command?(event) COMMAND_EVENT_TYPES.include?(event&.type) end
next_event()
click to toggle source
# File lib/temporal/workflow/history.rb, line 63 def next_event iterator.next rescue nil end
peek_event()
click to toggle source
# File lib/temporal/workflow/history.rb, line 67 def peek_event iterator.peek rescue nil end