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

Inherits:
Object
  • Object
show all
Defined in:
aws-flow-ruby/aws-flow/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.

Direct Known Subclasses

ServiceDecisionTaskProvider

Instance Method Summary (collapse)

Instance Method Details

- (DecisionTask) get_decision_task(replay_upto = nil)

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.

Parameters:

  • replay_upto (Fixnum) (defaults to: nil)

    Optional. The event_id of the last event to return. If set, returns the history only until the specified event is reached. If not set, then all available history will be returned. See HistoryEvent for more information.

Returns:

  • (DecisionTask)

    the workflow history encapsulated in a DecisionTask, optionally truncated to the event ID passed to replay_upto.



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 'aws-flow-ruby/aws-flow/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

- (Object) get_execution_info

Fetches the workflow execution information used to fill in the [DecisionTask][] details. Implementing classes must override this method.

Returns:



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

def get_execution_info; end

- (Object) get_history(page_token = nil)

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

Parameters:

  • page_token (defaults to: nil)

    Optional. A token used to get further pages of workflow history if all events could not be retrieved by the first call to the method.

Returns:

  • a list of HistoryEvents that comprise the workflow's available history.



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

def get_history(page_token = nil); end

- (Object) truncate_history(events, replay_upto = nil)

Truncates workflow history to a specified event id.

Parameters:

  • events

    the workflow history (events) to truncate.

  • replay_upto (Fixnum) (defaults to: nil)

    Optional. The event ID of the final HistoryEvent to return.

Returns:

  • the truncated list of events.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'aws-flow-ruby/aws-flow/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