Class: AWS::Flow::RetryPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/async_retrying_executor.rb

Overview

Represents a policy for retrying failed tasks.

Instance Method Summary collapse

Constructor Details

#initialize(retry_function, options) ⇒ RetryPolicy

Creates a new RetryPolicy instance

Parameters:

  • retry_function

    The method to be called for each retry attempt.

  • options

    A set of AWS::Flow::RetryOptions to modify the retry behavior.



89
90
91
92
93
94
95
96
97
# File 'lib/aws/decider/async_retrying_executor.rb', line 89

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
end

Instance Method Details

#isRetryable(failure) ⇒ true, false

Returns ‘true` if the task can be retried for this failure.

Parameters:

  • failure

    The failure to test.

Returns:

  • (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

Parameters:

  • first_attempt
  • time_of_recorded_failure
  • attempt
  • failure (defaults to: nil)


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