Class: AWS::Flow::DecisionTaskHandler

Inherits:
Object
  • Object
show all
Defined in:
aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb

Overview

A decision task handler to work with a WorkflowTaskPoller. Create a DecisionTaskHandler and pass it to WorkflowTaskPoller on construction.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DecisionTaskHandler) initialize(workflow_definition_map, options = nil)

Creates a new DecisionTaskHandler.

Parameters:

  • workflow_definition_map
  • options (defaults to: nil)

    An optional logger.



42
43
44
45
46
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb', line 42

def initialize(workflow_definition_map, options=nil)
  @workflow_definition_map = workflow_definition_map
  @logger = options.logger if options
  @logger ||= Utilities::LogFactory.make_logger(self)
end

Instance Attribute Details

- (Object) workflow_definition_map (readonly)

Returns the value of attribute workflow_definition_map



33
34
35
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb', line 33

def workflow_definition_map
  @workflow_definition_map
end

Class Method Details

+ (Object) from_workflow_class(workflow_class)

Factory method to create a DecisionTaskHandler instance given a workflow class



28
29
30
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb', line 28

def from_workflow_class workflow_class
  self.new(WorkflowDefinitionFactory.generate_definition_map(workflow_class))
end

Instance Method Details

- (AsyncDecider) create_async_decider(history_helper)

Creates a new asynchronous decider.

Parameters:

  • history_helper

Returns:



71
72
73
74
75
76
77
78
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb', line 71

def create_async_decider(history_helper)
  task = history_helper.get_decision_task
  workflow_type = task.workflow_type
  # TODO put in context correctly
  workflow_definition_factory = @workflow_definition_map[workflow_type]
  raise "No workflow definition for #{workflow_type.inspect}" if workflow_definition_factory.nil?
  AsyncDecider.new(workflow_definition_factory, history_helper, DecisionHelper.new)
end

- (Object) handle_decision_task(decision_task_iterator)

Handles a decision task.

Parameters:

  • decision_task_iterator


53
54
55
56
57
58
59
60
61
62
63
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/task_handler.rb', line 53

def handle_decision_task(decision_task_iterator)
  history_helper = HistoryHelper.new(decision_task_iterator)
  decider = create_async_decider(history_helper)
  decider.decide
  decisions = decider.get_decisions
  response = {:task_token => decider.task_token}
  context_data = decider.decision_helper.workflow_context_data
  response[:execution_context] = context_data.to_s unless context_data.nil?
  response[:decisions] = decisions unless decisions.nil?
  return response
end