Class: AWS::Flow::WorkflowClock
- Inherits:
-
Object
- Object
- AWS::Flow::WorkflowClock
- Defined in:
- lib/aws/decider/workflow_clock.rb
Overview
Represents a workflow clock that can create timers.
Instance Attribute Summary collapse
-
#replay_current_time_millis ⇒ Object
Gets or sets the current time in milliseconds for a replay.
-
#replaying ⇒ Object
Gets or sets the replaying status of the workflow clock.
Instance Method Summary collapse
-
#create_timer(delay_seconds, block) ⇒ Object
Create a new timer that executes the supplied block after a specified number of seconds.
-
#current_time ⇒ Time
Get the current time.
-
#initialize(decision_helper) ⇒ WorkflowClock
constructor
Create a new WorkflowClock instance.
Constructor Details
#initialize(decision_helper) ⇒ WorkflowClock
Create a new AWS::Flow::WorkflowClock instance.
35 36 37 38 39 40 41 |
# File 'lib/aws/decider/workflow_clock.rb', line 35 def initialize(decision_helper) #Map from timerIDs to OpenRequestInfo @scheduled_timers = {} = true @replay_current_time_millis @decision_helper = decision_helper end |
Instance Attribute Details
#replay_current_time_millis ⇒ Object
Gets or sets the current time in milliseconds for a replay.
27 28 29 |
# File 'lib/aws/decider/workflow_clock.rb', line 27 def replay_current_time_millis @replay_current_time_millis end |
#replaying ⇒ Object
Gets or sets the replaying status of the workflow clock.
24 25 26 |
# File 'lib/aws/decider/workflow_clock.rb', line 24 def end |
Instance Method Details
#create_timer(delay_seconds, block) ⇒ Object
Create a new timer that executes the supplied block after a specified number of seconds.
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 '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 ⇒ Time
Get the current time.
50 51 52 |
# File 'lib/aws/decider/workflow_clock.rb', line 50 def current_time @replay_current_time_millis end |