Class: ActiveJob::Retry::ExponentialBackoffStrategy

Inherits:
ConstantBackoffStrategy show all
Defined in:
lib/active_job/retry/exponential_backoff_strategy.rb

Instance Method Summary collapse

Methods inherited from ConstantBackoffStrategy

#should_retry?

Constructor Details

#initialize(options) ⇒ ExponentialBackoffStrategy

Returns a new instance of ExponentialBackoffStrategy.



6
7
8
9
10
11
# File 'lib/active_job/retry/exponential_backoff_strategy.rb', line 6

def initialize(options)
  ExponentialOptionsValidator.new(options).validate!
  @retry_limit          = options.fetch(:limit, 1)
  @fatal_exceptions     = options.fetch(:fatal_exceptions, [])
  @retryable_exceptions = options.fetch(:retryable_exceptions, nil)
end

Instance Method Details

#retry_delay(attempt, _exception) ⇒ Object



13
14
15
# File 'lib/active_job/retry/exponential_backoff_strategy.rb', line 13

def retry_delay(attempt, _exception)
  (attempt**4 + 15 + (rand(30) * (attempt + 1))).seconds
end