Class: Cadence::Workflow::History

Inherits:
Object
  • Object
show all
Defined in:
lib/cadence/workflow/history.rb,
lib/cadence/workflow/history/event.rb,
lib/cadence/workflow/history/window.rb,
lib/cadence/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/cadence/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/cadence/workflow/history.rb', line 7

def events
  @events
end

Instance Method Details

#last_completed_decision_taskObject



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

def last_completed_decision_task
  events.select { |event| event.type == 'DecisionTaskCompleted' }.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 decision 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 decision task related events (decision task started, completed, failed, etc)

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cadence/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 == 'DecisionTaskCompleted'
  end

  # Find the end of the window by exhausting all the commands
  window.add(next_event) while command?(peek_event)

  window.freeze
end