Class: AWS::Flow::Replayer::DecisionTaskProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/replayer.rb

Overview

This class is used by the Replayer to fetch the DecisionTask which will be used by the DecisionTaskHandler. This is an ‘abstract’ class. We need to extend it and implement get_history_page and get_execution_info methods to use it.

Direct Known Subclasses

ServiceDecisionTaskProvider

Instance Method Summary collapse

Instance Method Details

#get_decision_task(replay_upto = nil) ⇒ Object

This method fetches the workflow history and wraps all the history events, workflow type, workflow execution inside a decision task for the decider to work on



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aws/replayer.rb', line 16

def get_decision_task(replay_upto = nil)
  # Get workflow execution info so that we can populate the workflowType
  # and execution fields of the DecisionTask.
  execution_info = get_execution_info
  events = get_history

  # Truncate history if replay_upto variable is set so that we only
  # replay the history till the specified event
  events = truncate_history(events, replay_upto)
  return nil if events.nil?

  # Generate the hash to instantiate a DecisionTask. We can set
  # taskToken and nextPageToken to nil since we don't need the values
  # in the replayer
  data = {
    'taskToken' => nil,
    'workflowExecution' => execution_info["execution"],
    'workflowType' => execution_info["workflowType"],
    'events' => events,
    'nextPageToken' => nil
  }
  AWS::SimpleWorkflow::DecisionTask.new(nil, nil, data)
end

#get_execution_infoObject

This method is used to fetch the WorkflowExecutionInfo to fill in the DecisionTask details. Implementing classes must override this method



61
# File 'lib/aws/replayer.rb', line 61

def get_execution_info; end

#get_history(page_token = nil) ⇒ Object

This method is used to fetch the actual history. Implementing classes must override this method.



57
# File 'lib/aws/replayer.rb', line 57

def get_history(page_token = nil); end

#truncate_history(events, replay_upto = nil) ⇒ Object

This method truncates the workflow history to the event_id specified by the replay_upto variable



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws/replayer.rb', line 42

def truncate_history(events, replay_upto = nil)
  return nil if events.nil? || events.empty?

  # Just return the original array of events if replay_upto is not set
  # or if the number of events is less than replay_upto
  return events if replay_upto.nil? || events.last['eventId'] <= replay_upto

  # Select the events whose eventId is lesser than replay_upto
  truncated = events.select { |event| event['eventId'] <= replay_upto }
  return nil if truncated.empty?
  truncated
end