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

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

Overview

This class is abstract.

Implement the ‘get_history_page` and `get_execution_info` methods to use it.

Used by AWS::Flow::Replayer to fetch a [DecisionTask][] which will be used by DecisionTaskHandler.

[DecisionTask]: docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/DecisionTask.html

Direct Known Subclasses

ServiceDecisionTaskProvider

Instance Method Summary collapse

Instance Method Details

#get_decision_task(replay_upto = nil) ⇒ DecisionTask

Fetches the workflow history and wraps all the history events, workflow type and workflow execution inside a decision task for the decider to work on.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aws/replayer.rb', line 36

def get_decision_task(replay_upto = nil)

  # Get workflow execution info so that we can populate the workflowType
  # and execution fields of the [DecisionTask][].
  #
  # [DecisionTask]: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/DecisionTask.html
  #
  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.
  #
  # [DecisionTask]: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/SimpleWorkflow/DecisionTask.html
  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

Fetches the workflow execution information used to fill in the

DecisionTask][

details. Implementing classes must override this

method.



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

def get_execution_info; end

#get_history(page_token = nil) ⇒ Object

Fetches the workflow history. Implementing classes must override this method.



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

def get_history(page_token = nil); end

#truncate_history(events, replay_upto = nil) ⇒ Object

Truncates workflow history to a specified event id.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/aws/replayer.rb', line 78

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