Class: AWS::Flow::RetryPolicy
- Inherits:
-
Object
- Object
- AWS::Flow::RetryPolicy
- Defined in:
- lib/aws/decider/async_retrying_executor.rb
Overview
Represents a policy for retrying failed tasks.
Instance Method Summary collapse
-
#initialize(retry_function, options) ⇒ RetryPolicy
constructor
Creates a new RetryPolicy instance.
-
#isRetryable(failure) ⇒ true, false
Returns ‘true` if the task can be retried for this failure.
-
#next_retry_delay_seconds(first_attempt, time_of_recorded_failure, attempt, failure = nil, execution_id) ⇒ Object
Schedules a new retry attempt.
Constructor Details
#initialize(retry_function, options) ⇒ RetryPolicy
Creates a new RetryPolicy instance
89 90 91 92 93 94 95 96 97 |
# File 'lib/aws/decider/async_retrying_executor.rb', line 89 def initialize(retry_function, ) @retry_function = retry_function @exceptions_to_exclude = .exceptions_to_exclude @exceptions_to_include = .exceptions_to_include @max_attempts = .maximum_attempts @retries_per_exception = .retries_per_exception @should_jitter = .should_jitter @jitter_function = .jitter_function end |
Instance Method Details
#isRetryable(failure) ⇒ true, false
Returns ‘true` if the task can be retried for this failure.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/aws/decider/async_retrying_executor.rb', line 105 def isRetryable(failure) if failure.respond_to? :cause failure_class = failure.cause.class else failure_class = failure.class end return true if @exceptions_to_exclude.empty? && @exceptions_to_include.empty? raise "#{failure} appears in both exceptions_to_include and exceptions_to_exclude" if @exceptions_to_exclude.include?(failure_class) && @exceptions_to_include.include?(failure_class) # In short, default to false # the second part of the statement does an intersection of the 2 arrays to see if any of the ancestors of # failure exists in @exceptions_to_include return (!@exceptions_to_exclude.include?(failure_class) && !(@exceptions_to_include & failure_class.ancestors).empty?) #return (!@exceptions_to_exclude.include?(failure) && @exceptions_to_include.include?(failure)) end |
#next_retry_delay_seconds(first_attempt, time_of_recorded_failure, attempt, failure = nil, execution_id) ⇒ Object
Schedules a new retry attempt
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/aws/decider/async_retrying_executor.rb', line 132 def next_retry_delay_seconds(first_attempt, time_of_recorded_failure, attempt, failure = nil, execution_id) if attempt.values.reduce(0, :+) < 2 raise "This is bad, you have less than 2 attempts. More precisely, #{attempt} attempts" end if @max_attempts && @max_attempts != "NONE" return -1 if attempt.values.reduce(0, :+) > @max_attempts + 1 end if failure && @retries_per_exception && @retries_per_exception.keys.include?(failure.class) return -1 if attempt[failure.class] > @retries_per_exception[failure.class] end return -1 if failure == nil # Check to see if we should jitter or not and pass in the jitter function to retry function accordingly. retry_seconds = @retry_function.call(first_attempt, time_of_recorded_failure, attempt) if @should_jitter retry_seconds += @jitter_function.call(execution_id, retry_seconds/2) end return retry_seconds end |