Module: ActiveJob::Retry

Defined in:
lib/active_job/retry.rb,
lib/active_job/retry/errors.rb,
lib/active_job/retry/version.rb,
lib/active_job/retry/constant_backoff_strategy.rb,
lib/active_job/retry/variable_backoff_strategy.rb,
lib/active_job/retry/constant_options_validator.rb,
lib/active_job/retry/variable_options_validator.rb,
lib/active_job/retry/exponential_backoff_strategy.rb,
lib/active_job/retry/exponential_options_validator.rb

Defined Under Namespace

Modules: ClassMethods Classes: ConstantBackoffStrategy, ConstantOptionsValidator, ExponentialBackoffStrategy, ExponentialOptionsValidator, InvalidConfigurationError, UnsupportedAdapterError, VariableBackoffStrategy, VariableOptionsValidator

Constant Summary collapse

PROBLEMATIC_ADAPTERS =
[
  'ActiveJob::QueueAdapters::InlineAdapter',
  'ActiveJob::QueueAdapters::QuAdapter',
  'ActiveJob::QueueAdapters::QueueClassicAdapter',
  'ActiveJob::QueueAdapters::SneakersAdapter',
  'ActiveJob::QueueAdapters::SuckerPunchAdapter'
].freeze
VERSION =
'0.5.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/active_job/retry.rb', line 24

def self.included(base)
  if PROBLEMATIC_ADAPTERS.include?(ActiveJob::Base.queue_adapter.name)
    warn("#{ActiveJob::Base.queue_adapter.name} does not support delayed retries, " \
         'so does not work with ActiveJob::Retry. You may experience strange ' \
         'behaviour.')
  end

  base.extend(ClassMethods)
end

Instance Method Details

#deserialize(job_data) ⇒ Object



79
80
81
82
# File 'lib/active_job/retry.rb', line 79

def deserialize(job_data)
  super(job_data)
  @retry_attempt = job_data['retry_attempt']
end

#rescue_with_handler(exception) ⇒ Object

Override ‘rescue_with_handler` to make sure our catch is before callbacks, so `rescue_from`s will only be run after any retry attempts have been exhausted.



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/active_job/retry.rb', line 94

def rescue_with_handler(exception)
  unless self.class.backoff_strategy.should_retry?(retry_attempt, exception)
    return super
  end

  this_delay = self.class.backoff_strategy.retry_delay(retry_attempt, exception)
  # TODO: This breaks DelayedJob and Resque for some weird ActiveSupport reason.
  # logger.info("Retrying (attempt #{retry_attempt + 1}, waiting #{this_delay}s)")
  @retry_attempt += 1
  retry_job(wait: this_delay)

  true # Exception has been handled
end

#retry_attemptObject



84
85
86
# File 'lib/active_job/retry.rb', line 84

def retry_attempt
  @retry_attempt ||= 1
end

#serializeObject

Storage of attempt number #



75
76
77
# File 'lib/active_job/retry.rb', line 75

def serialize
  super.merge('retry_attempt' => retry_attempt)
end