Class: Temporal::Workflow::History

Inherits:
Object
  • Object
show all
Defined in:
lib/temporal/workflow/history.rb,
lib/temporal/workflow/history/event.rb,
lib/temporal/workflow/history/window.rb,
lib/temporal/workflow/history/event_target.rb

Defined Under Namespace

Classes: Event, EventTarget, Window

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ History

Returns a new instance of History.



9
10
11
12
# File 'lib/temporal/workflow/history.rb', line 9

def initialize(events)
  @events = events.map { |event| History::Event.new(event) }
  @iterator = @events.each
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



7
8
9
# File 'lib/temporal/workflow/history.rb', line 7

def events
  @events
end

Instance Method Details

#last_completed_workflow_taskObject



14
15
16
# File 'lib/temporal/workflow/history.rb', line 14

def last_completed_workflow_task
  events.select { |event| event.type == 'WORKFLOW_TASK_COMPLETED' }.last
end

#next_windowObject

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:

  1. Events that happened since the last window (timer fired, activity completed, etc)

  2. A workflow task related events (workflow task started, completed, failed, etc)

  3. Commands issued by the last workflow task (^) (schedule activity, start timer, etc)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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