Class: StatesLanguageMachine::States::RetryPolicy
- Inherits:
-
Object
- Object
- StatesLanguageMachine::States::RetryPolicy
- Defined in:
- lib/ruby_slm/states/task.rb
Overview
Retry policy class
Instance Attribute Summary collapse
-
#backoff_rate ⇒ Object
readonly
Returns the value of attribute backoff_rate.
-
#error_equals ⇒ Object
readonly
Returns the value of attribute error_equals.
-
#interval_seconds ⇒ Object
readonly
Returns the value of attribute interval_seconds.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
Instance Method Summary collapse
-
#initialize(definition) ⇒ RetryPolicy
constructor
A new instance of RetryPolicy.
- #matches?(error, attempt) ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(definition) ⇒ RetryPolicy
Returns a new instance of RetryPolicy.
439 440 441 442 443 444 445 |
# File 'lib/ruby_slm/states/task.rb', line 439 def initialize(definition) @error_equals = Array(definition["ErrorEquals"]) @interval_seconds = definition["IntervalSeconds"] || 1 @max_attempts = definition["MaxAttempts"] || 3 @backoff_rate = definition["BackoffRate"] || 2.0 @max_delay = definition["MaxDelay"] || 3600 # 1 hour default end |
Instance Attribute Details
#backoff_rate ⇒ Object (readonly)
Returns the value of attribute backoff_rate.
437 438 439 |
# File 'lib/ruby_slm/states/task.rb', line 437 def backoff_rate @backoff_rate end |
#error_equals ⇒ Object (readonly)
Returns the value of attribute error_equals.
437 438 439 |
# File 'lib/ruby_slm/states/task.rb', line 437 def error_equals @error_equals end |
#interval_seconds ⇒ Object (readonly)
Returns the value of attribute interval_seconds.
437 438 439 |
# File 'lib/ruby_slm/states/task.rb', line 437 def interval_seconds @interval_seconds end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
437 438 439 |
# File 'lib/ruby_slm/states/task.rb', line 437 def max_attempts @max_attempts end |
Instance Method Details
#matches?(error, attempt) ⇒ Boolean
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/ruby_slm/states/task.rb', line 447 def matches?(error, attempt) return false if attempt >= @max_attempts @error_equals.any? do |error_match| case error_match when "States.ALL" true when "States.Timeout" error.is_a?(TaskTimeoutError) when "States.TaskFailed" error.is_a?(StandardError) && !error.is_a?(TaskTimeoutError) when "States.Permissions" error.is_a?(SecurityError) || error..include?("permission") else error.class.name == error_match || error..include?(error_match) end end end |
#validate! ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/ruby_slm/states/task.rb', line 466 def validate! if @error_equals.empty? raise DefinitionError, "Retry policy must specify ErrorEquals" end if @interval_seconds < 0 raise DefinitionError, "IntervalSeconds must be non-negative" end if @max_attempts < 0 raise DefinitionError, "MaxAttempts must be non-negative" end end |