Module: AWS::Flow::Workflows::InstanceMethods

Defined in:
lib/aws/decider/decider.rb

Overview

Instance methods for DecisionContext.

Instance Method Summary collapse

Instance Method Details

#activity_client(name = nil, &block) ⇒ Object

Sets the activity client for this decision context.

Parameters:

  • name (defaults to: nil)

    The name of the activity client.

  • block

    A block of ActivityOptions for the activity client.



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/aws/decider/decider.rb', line 438

def activity_client(name=nil, &block)
  options = Utilities::interpret_block_for_options(ActivityOptions, block)
  begin
    activity_class = get_const(options.prefix_name)
  rescue Exception => e
    #pass
  end
  activity_options = {}
  if activity_class
    values = activity_class.activities.map{|x| [x.name.split(".").last.to_sym, x.options]}
    activity_options = Hash[*values.flatten]
  end
  client = GenericActivityClient.new(self.decision_helper, options)
  self.class.send(:define_method, name) { client }  if ! name.nil?
  client
end

#async_create_timer(delay_seconds, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deprecated.

Use #create_timer_async instead.

Creates an asynchronous timer on the workflow that executes the supplied block after a specified delay.

Parameters:

  • delay_seconds

    The number of seconds to delay before executing the block.

  • block

    The block to execute when the timer expires.



475
476
477
# File 'lib/aws/decider/decider.rb', line 475

def async_create_timer(delay_seconds, &block)
  task { self.decision_context.workflow_clock.create_timer(delay_seconds, block) }
end

#continue_as_new(*args, &block) ⇒ Object

Restarts the workflow as a new workflow execution.

Parameters:



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/aws/decider/decider.rb', line 497

def continue_as_new(*args, &block)
  continue_as_new_options = Utilities::interpret_block_for_options(ContinueAsNewOptions, block)
  @data_converter ||= YAMLDataConverter.new
  if ! args.empty?
    input = @data_converter.dump args
    continue_as_new_options.input = input
  end
  known_workflows = self.class.workflows
  # If there is only one workflow, we can unambiguously say that we should use that one.

  if known_workflows.length == 1
    continue_as_new_options.precursors << known_workflows.first.options
  end
  # If we can find a name that matches, use that one.
  if continue_as_new_options.execution_method
    matching_option = self.class.workflows.map(&:options).find {|x| x.execution_method == continue_as_new_options.execution_method }
    continue_as_new_options.precursors << matching_option unless matching_option.nil?
  end
  self.decision_context.workflow_context.continue_as_new_options = continue_as_new_options
end

#create_timer(delay_seconds, &block) ⇒ Object

Creates a timer on the workflow that executes the supplied block after a specified delay.

Parameters:

  • delay_seconds

    The number of seconds to delay before executing the block.

  • block

    The block to execute when the timer expires.



463
464
465
# File 'lib/aws/decider/decider.rb', line 463

def create_timer(delay_seconds, &block)
  self.decision_context.workflow_clock.create_timer(delay_seconds, block)
end

#create_timer_async(delay_seconds, &block) ⇒ Object

Creates an asynchronous timer on the workflow that executes the supplied block after a specified delay.

Parameters:

  • delay_seconds

    The number of seconds to delay before executing the block.

  • block

    The block to execute when the timer expires.



484
485
486
# File 'lib/aws/decider/decider.rb', line 484

def create_timer_async(delay_seconds, &block)
  task { self.decision_context.workflow_clock.create_timer(delay_seconds, block) }
end

#decision_contextDecisionContext

Returns the DecisionContext instance.

Returns:



405
406
407
# File 'lib/aws/decider/decider.rb', line 405

def decision_context
  FlowFiber.current[:decision_context]
end

#decision_helperObject



425
426
427
# File 'lib/aws/decider/decider.rb', line 425

def decision_helper
  FlowFiber.current[:decision_context].decision_helper
end

#run_idObject

Returns the decision helper for the decision context. This should be an instance of DecisionHelper or a class derived from it.



421
422
423
# File 'lib/aws/decider/decider.rb', line 421

def run_id
  self.decision_context.workflow_context.decision_task.workflow_execution.run_id
end

#workflow_idObject

Returns the workflow ID.

Returns:

  • The workflow ID.



415
416
417
# File 'lib/aws/decider/decider.rb', line 415

def workflow_id
  self.decision_context.workflow_context.decision_task.workflow_execution.workflow_id
end