Module: ActiveJob::Retry::ClassMethods

Defined in:
lib/active_job/retry.rb

Overview

Configuration #

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backoff_strategyObject (readonly)

Returns the value of attribute backoff_strategy.



39
40
41
# File 'lib/active_job/retry.rb', line 39

def backoff_strategy
  @backoff_strategy
end

Instance Method Details

#backoff_strategy_valid?(backoff_strategy) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/active_job/retry.rb', line 63

def backoff_strategy_valid?(backoff_strategy)
  backoff_strategy.respond_to?(:should_retry?) &&
    backoff_strategy.respond_to?(:retry_delay) &&
    backoff_strategy.method(:should_retry?).arity == 2 &&
    backoff_strategy.method(:retry_delay).arity == 2
end

#constant_retry(options) ⇒ Object



41
42
43
# File 'lib/active_job/retry.rb', line 41

def constant_retry(options)
  retry_with(ConstantBackoffStrategy.new(options))
end

#exponential_retry(options) ⇒ Object



49
50
51
# File 'lib/active_job/retry.rb', line 49

def exponential_retry(options)
  retry_with(ExponentialBackoffStrategy.new(options))
end

#retry_with(backoff_strategy) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/active_job/retry.rb', line 53

def retry_with(backoff_strategy)
  unless backoff_strategy_valid?(backoff_strategy)
    raise InvalidConfigurationError,
          'Backoff strategies must define `should_retry?(attempt, exception)`, ' \
          'and `retry_delay(attempt, exception)`.'
  end

  @backoff_strategy = backoff_strategy
end

#variable_retry(options) ⇒ Object



45
46
47
# File 'lib/active_job/retry.rb', line 45

def variable_retry(options)
  retry_with(VariableBackoffStrategy.new(options))
end