Class: AWS::Flow::WorkflowClock

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

Overview

Represents a workflow clock that can create timers.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (WorkflowClock) initialize(decision_helper)

Create a new AWS::Flow::WorkflowClock instance.

Parameters:

  • decision_helper (DecisionHelper)

    The decision helper used by the workflow clock to schedule and execute timers.



35
36
37
38
39
40
41
# File 'aws-flow-ruby/aws-flow/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

Instance Attribute Details

- (Object) replay_current_time_millis

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



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

def replay_current_time_millis
  @replay_current_time_millis
end

- (Object) replaying

Gets or sets the replaying status of the workflow clock.



24
25
26
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/workflow_clock.rb', line 24

def replaying
  @replaying
end

Instance Method Details

- (Object) create_timer(delay_seconds, block)

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

Parameters:

  • delay_seconds

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

  • block

    A block to execute after delay_seconds has expired.

Raises:

  • (IllegalArgumentException)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'aws-flow-ruby/aws-flow/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

- (Time) current_time

Get the current time.

Returns:

  • (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.



50
51
52
# File 'aws-flow-ruby/aws-flow/lib/aws/decider/workflow_clock.rb', line 50

def current_time
  @replay_current_time_millis
end