class Sidekiq::Middleware::RetryJobs

Overview

Automatically retry jobs that fail in Sidekiq. Sidekiq's retry support assumes a typical development lifecycle:

  1. Push some code changes with a bug in it.
  2. Bug causes job processing to fail, Sidekiq's middleware captures the job and pushes it onto a retry queue.
  3. Sidekiq retries jobs in the retry queue multiple times with an exponential delay, the job continues to fail.
  4. After a few days, a developer deploys a fix. The job is reprocessed successfully.
  5. Once retries are exhausted, Sidekiq will give up and move the job to the Dead Job Queue (aka morgue) where it must be dealt with manually in the Web UI.
  6. After 6 months on the DJQ, Sidekiq will discard the job.

A job looks like:

{ 'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => true }

The 'retry' option also accepts a number (in place of 'true'):

{ 'class' => 'HardWorker', 'args' => [1, 2, 'foo'], 'retry' => 5 }

The job will be retried this number of times before giving up. (If simply 'true', Sidekiq retries 25 times)

We'll add a bit more data to the job to support retries:

We don't store the backtrace by default as that can add a lot of overhead to the job and everyone is using an error service, right?

The default number of retry attempts is 25 which works out to about 3 weeks of retries. Limit the number of retries for a particular worker with:

class MyWorker include Sidekiq::Worker sidekiq_options do |job| job.retry = 10 end end

Defined in:

sidekiq/server/retry_jobs.cr

Constant Summary

DEFAULT_MAX_RETRY_ATTEMPTS = 25

Constructors

Instance Method Summary

Instance methods inherited from class Sidekiq::Middleware::Entry

call(job : Sidekiq::Job, ctx : Context, &block : -> Bool) : Bool call

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def attempt_retry(job, ctx, exception) #

[View source]
def call(job, ctx, &) : Bool #

[View source]
def delay_for(job, count, exception) #

[View source]
def retries(retry) #

The retries option can be true, false, nil or Int64.


[View source]
def retries_exhausted(job, ctx, exception) #

[View source]
def seconds_to_delay(count) #

delayed_job uses the same basic formula


[View source]
def send_to_morgue(job, ctx) #

[View source]
def traces(trace) #

The backtrace option can be true, false, nil or Int64.


[View source]