Class: StatesLanguageMachine::States::Task
- Inherits:
-
Base
- Object
- StatesLanguageMachine::State
- Base
- StatesLanguageMachine::States::Task
- Defined in:
- lib/ruby_slm/states/task.rb
Constant Summary collapse
- INTRINSIC_FUNCTIONS =
Intrinsic functions supported by AWS Step Functions
%w[ States.Format States.StringToJson States.JsonToString States.Array States.ArrayPartition States.ArrayContains States.ArrayRange States.ArrayGetItem States.ArrayLength States.ArrayUnique States.Base64Encode States.Base64Decode States.Hash States.JsonMerge States.MathRandom States.MathAdd States.StringSplit States.UUID ].freeze
Instance Attribute Summary collapse
-
#catch ⇒ Array<Hash>
readonly
The catch configuration.
-
#comment ⇒ String?
readonly
The comment for the state.
-
#credentials ⇒ String?
readonly
The credentials ARN for the task.
-
#heartbeat_seconds ⇒ Integer?
readonly
The heartbeat interval in seconds.
-
#input_path ⇒ String?
readonly
The input path.
-
#output_path ⇒ String?
readonly
The output path.
-
#parameters ⇒ Hash
readonly
The parameters to pass to the resource.
-
#resource ⇒ String
readonly
The resource ARN or URI to invoke.
-
#result_path ⇒ String?
readonly
The result path.
-
#result_selector ⇒ Hash?
readonly
The result selector.
-
#retry ⇒ Array<Hash>
readonly
The retry configuration.
-
#timeout_seconds ⇒ Integer?
readonly
The timeout in seconds for the task.
Attributes inherited from Base
Attributes inherited from StatesLanguageMachine::State
#end_state, #name, #next_state, #type
Instance Method Summary collapse
-
#catch_policy_for(error) ⇒ CatchPolicy?
Check if this task has a catch handler for a specific error.
-
#execute(execution, input) ⇒ Hash
The output data from the state.
-
#initialize(name, definition) ⇒ Task
constructor
A new instance of Task.
-
#retry_policy_for(error, attempt) ⇒ RetryPolicy?
Check if this task supports retry for a specific error.
Methods inherited from StatesLanguageMachine::State
Constructor Details
#initialize(name, definition) ⇒ Task
Returns a new instance of Task.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_slm/states/task.rb', line 47 def initialize(name, definition) super @resource = definition["Resource"] @timeout_seconds = definition["TimeoutSeconds"] @heartbeat_seconds = definition["HeartbeatSeconds"] @parameters = definition["Parameters"] || {} @result_path = definition["ResultPath"] @result_selector = definition["ResultSelector"] @input_path = definition["InputPath"] @output_path = definition["OutputPath"] @credentials = definition["Credentials"] @comment = definition["Comment"] @retry = definition["Retry"] || [] @catch = definition["Catch"] || [] # Initialize retry and catch objects @retry_objects = @retry.map { |r| RetryPolicy.new(r) } @catch_objects = @catch.map { |c| CatchPolicy.new(c) } validate! end |
Instance Attribute Details
#catch ⇒ Array<Hash> (readonly)
Returns the catch configuration.
19 20 21 |
# File 'lib/ruby_slm/states/task.rb', line 19 def catch @catch end |
#comment ⇒ String? (readonly)
Returns the comment for the state.
33 34 35 |
# File 'lib/ruby_slm/states/task.rb', line 33 def comment @comment end |
#credentials ⇒ String? (readonly)
Returns the credentials ARN for the task.
31 32 33 |
# File 'lib/ruby_slm/states/task.rb', line 31 def credentials @credentials end |
#heartbeat_seconds ⇒ Integer? (readonly)
Returns the heartbeat interval in seconds.
15 16 17 |
# File 'lib/ruby_slm/states/task.rb', line 15 def heartbeat_seconds @heartbeat_seconds end |
#input_path ⇒ String? (readonly)
Returns the input path.
27 28 29 |
# File 'lib/ruby_slm/states/task.rb', line 27 def input_path @input_path end |
#output_path ⇒ String? (readonly)
Returns the output path.
29 30 31 |
# File 'lib/ruby_slm/states/task.rb', line 29 def output_path @output_path end |
#parameters ⇒ Hash (readonly)
Returns the parameters to pass to the resource.
21 22 23 |
# File 'lib/ruby_slm/states/task.rb', line 21 def parameters @parameters end |
#resource ⇒ String (readonly)
Returns the resource ARN or URI to invoke.
11 12 13 |
# File 'lib/ruby_slm/states/task.rb', line 11 def resource @resource end |
#result_path ⇒ String? (readonly)
Returns the result path.
23 24 25 |
# File 'lib/ruby_slm/states/task.rb', line 23 def result_path @result_path end |
#result_selector ⇒ Hash? (readonly)
Returns the result selector.
25 26 27 |
# File 'lib/ruby_slm/states/task.rb', line 25 def result_selector @result_selector end |
#retry ⇒ Array<Hash> (readonly)
Returns the retry configuration.
17 18 19 |
# File 'lib/ruby_slm/states/task.rb', line 17 def retry @retry end |
#timeout_seconds ⇒ Integer? (readonly)
Returns the timeout in seconds for the task.
13 14 15 |
# File 'lib/ruby_slm/states/task.rb', line 13 def timeout_seconds @timeout_seconds end |
Instance Method Details
#catch_policy_for(error) ⇒ CatchPolicy?
Check if this task has a catch handler for a specific error
102 103 104 105 106 |
# File 'lib/ruby_slm/states/task.rb', line 102 def catch_policy_for(error) @catch_objects.find do |catch_policy| catch_policy.matches?(error) end end |
#execute(execution, input) ⇒ Hash
Returns the output data from the state.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruby_slm/states/task.rb', line 72 def execute(execution, input) execution.logger&.info("Executing task state: #{@name}") execution.context[:current_state] = @name execution.context[:state_entered_time] = Time.now begin if @timeout_seconds || @heartbeat_seconds execute_with_timeout(execution, input) else execute_without_timeout(execution, input) end rescue => error handle_execution_error(execution, error, input) end end |
#retry_policy_for(error, attempt) ⇒ RetryPolicy?
Check if this task supports retry for a specific error
92 93 94 95 96 |
# File 'lib/ruby_slm/states/task.rb', line 92 def retry_policy_for(error, attempt) @retry_objects.find do |retry_policy| retry_policy.matches?(error, attempt) end end |