class AWS::Flow::RetryPolicy
Represents a policy for retrying failed tasks.
Public Class Methods
new(retry_function, options)
click to toggle source
Creates a new ‘RetryPolicy` instance.
@param retry_function
The method that will be called for each retry attempt.
@param options
A set of {RetryOptions} used to modify the retry behavior.
# File lib/aws/decider/async_retrying_executor.rb, line 109 def initialize(retry_function, options) @retry_function = retry_function @exceptions_to_exclude = options.exceptions_to_exclude @exceptions_to_include = options.exceptions_to_include @max_attempts = options.maximum_attempts @retries_per_exception = options.retries_per_exception @should_jitter = options.should_jitter @jitter_function = options.jitter_function @options = options end
Public Instance Methods
isRetryable(failure)
click to toggle source
@param failure
The failure to test.
@return [true, false]
Returns `true` if the task can be retried for this failure; `false` otherwise.
# File lib/aws/decider/async_retrying_executor.rb, line 127 def isRetryable(failure) if failure.respond_to?(:cause) && !failure.cause.nil? 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, attempts, failure = nil, execution_id)
click to toggle source
Schedules a new retry attempt with an initial delay.
@param first_attempt
The time to delay before the first retry attempt is made.
@param time_of_recorded_failure
@param attempts
The number of retry attempts to make before the task is considered to be failed.
@param failure
The type of failure to retry. If not specified, then all types of failures will be retried.
@param execution_id
# File lib/aws/decider/async_retrying_executor.rb, line 162 def next_retry_delay_seconds(first_attempt, time_of_recorded_failure, attempts, failure = nil, execution_id) if attempts.values.reduce(0, :+) < 2 raise "This is bad, you have less than 2 attempts. More precisely, #{attempts} attempts" end if @max_attempts && @max_attempts != "NONE" return -1 if attempts.values.reduce(0, :+) > @max_attempts + 1 end if failure && @retries_per_exception && @retries_per_exception.keys.include?(failure.class) return -1 if attempts[failure.class] > @retries_per_exception[failure.class] end return -1 if failure == nil # For reverse compatbility purposes, we must ensure that this function # can take 3 arguments. However, we must also consume options in order # for the default retry function to work correctly. Because we support # ruby 1.9, we cannot use default arguments in a lambda, so we resort to # the following workaround to supply a 4th argument if the function # expects it. call_args = [first_attempt, time_of_recorded_failure, attempts] call_args << @options if @retry_function.arity == 4 retry_seconds = @retry_function.call(*call_args) # Check to see if we should jitter or not and pass in the jitter # function to retry function accordingly. if @should_jitter && retry_seconds > 0 retry_seconds += @jitter_function.call(execution_id, retry_seconds/2) end return retry_seconds end