module Resque::Pertry::Retry

Public Instance Methods

delay_before_retry(model) click to toggle source
# File lib/resque/pertry/retry.rb, line 161
def delay_before_retry(model)
  if self.class.retry_delays
    self.class.retry_delays[ model.attempt - 1 ]
  else
    self.class.retry_delay || 0
  end
end
exception_whitelisted?(model, exception) click to toggle source
# File lib/resque/pertry/retry.rb, line 137
def exception_whitelisted?(model, exception)
  # all exceptions are whitelisted implicitly if we didn't set the exception list
  return true unless self.class.retry_exceptions

  self.class.retry_exceptions.include?(exception.class)
end
max_attempt_reached?(model) click to toggle source
# File lib/resque/pertry/retry.rb, line 151
def max_attempt_reached?(model)
  if self.class.retry_attempts && self.class.retry_attempts < model.attempt
    true
  elsif self.class.retry_delays && self.class.retry_delays.size < model.attempt
    true
  else
    false
  end
end
retry!(model, exception) click to toggle source

Retry the job

# File lib/resque/pertry/retry.rb, line 128
def retry!(model, exception)
  return false unless retry?(model, exception)

  delay = delay_before_retry(model)
  return false unless delay

  Resque.enqueue_in(delay, self.class, payload)
end
retry?(model, exception) click to toggle source

Checks if we can retry

# File lib/resque/pertry/retry.rb, line 112
def retry?(model, exception)
  # check the obvious
  return false unless model
  return false if model.finnished?

  # job has used up all it's allowed attempts
  return false if max_attempt_reached?(model)

  # job exception is not whitelisted for retries
  return false unless exception_whitelisted?(model, exception)

  # seems like we should be able to retry this job
  return true
end
ttl_expired?(model) click to toggle source
# File lib/resque/pertry/retry.rb, line 144
def ttl_expired?(model)
  # if we didn't set a ttl, it hasn't expired
  return false unless self.class.retry_ttl

  model.expired?
end