class AWS::Flow::WorkflowClock

Represents a workflow clock that can create timers.

Attributes

replay_current_time_millis[RW]

Gets or sets the current time in milliseconds for a replay.

replaying[RW]

Gets or sets the replaying status of the workflow clock.

Public Class Methods

new(decision_helper) click to toggle source

Create a new {WorkflowClock} instance.

@param [DecisionHelper] decision_helper

The decision helper used by the workflow clock to schedule and execute timers.
# File lib/aws/decider/workflow_clock.rb, line 35
def initialize(decision_helper)
  #Map from timerIDs to OpenRequestInfo
  @scheduled_timers = {}
  @replaying = true
  @replay_current_time_millis
  @decision_helper = decision_helper
end

Public Instance Methods

create_timer(delay_seconds, block) click to toggle source

Create a new timer that executes the supplied block after a specified number of seconds.

@param delay_seconds

The number of seconds to wait before executing the block. Set to 0 to execute the block immediately.

@param block

A block to execute after `delay_seconds` has expired.
# File lib/aws/decider/workflow_clock.rb, line 62
def create_timer(delay_seconds, block)
  raise IllegalArgumentException if delay_seconds < 0
  if delay_seconds == 0
    if block
      return block.call
    else
      return
    end
  end
  attributes = {}
  timer_id = @decision_helper.get_next_id(:Timer)
  attributes[:timer_id] = timer_id
  attributes[:start_to_fire_timeout] = delay_seconds.to_s
  open_request = OpenRequestInfo.new
  open_request.blocking_promise = Future.new
  if block
    open_request.result = task do
      open_request.blocking_promise.get
      block.call
    end
  else
    open_request.result = open_request.blocking_promise
  end
  external_task do |t|
    t.initiate_task do |handle|
      open_request.completion_handle = handle
      @decision_helper.scheduled_timers[timer_id.to_s] = open_request
      @decision_helper[timer_id.to_s] = TimerDecisionStateMachine.new(timer_id, attributes)
    end
    t.cancellation_handler do |handle, cause|
      state_machine = @decision_helper[timer_id]
      open_request = @decision_helper.scheduled_timers.delete(timer_id)
      open_request.completion_handle.complete
      state_machine.consume(:cancel)
      state_machine.cancelled = true
    end
  end
  return open_request.result.get
end
current_time() click to toggle source

Get the current time.

@return [Time]

A `Time` object initialized to the current time in milliseconds for a replay. This is the same time that
is provided by the `:replay_current_time_millis` attribute.
# File lib/aws/decider/workflow_clock.rb, line 50
def current_time
  @replay_current_time_millis
end