Skip to content

Job Format

Mike Perham edited this page Feb 5, 2016 · 15 revisions

Sidekiq serializes jobs to Redis in JSON format. Each Job is a simple Hash of data.

Job

At bare minimum, a job requires five fields:

{
  "class": "SomeWorker",
  "jid": "b4a577edbccf1d805744efa9", // 12-byte random number as 24 char hex string
  "args": [1, "arg", true],
  "created_at": 1234567890,
  "enqueued_at": 1234567890
}

args is splatted into an instance of the worker class's perform method. Note that enqueued_at isn't added to the payload for scheduled jobs. They get the enqueued_at field when they are pushed onto a queue.

Worker Options

When a job is serialized, the options for the Worker are serialized as part of the job payload:

{
  "queue": "default",
  "retry": true
}

Scheduled Jobs

The at element stores when a job is scheduled to execute, in Unix epoch format:

{
  "at": 1234567890.123
}

Retries

Sidekiq's retry feature adds several elements to the job payload, necessary for documenting the error in the UI:

{
  "retry_count": 2, // number of times we've retried so far
  "error_message": "wrong number of arguments (2 for 3)", // the exception message
  "error_class": "ArgumentError", // the exception class
  "error_backtrace": ["line 0", "line 1", ...], // some or all of the exception's backtrace, optional, array of strings
  "failed_at": 1234567890, // the first time the job failed
  "retried_at": 1234567890 // the last time the job failed
}

The last two items are timestamps stored as epoch integers.