Skip to content

Job Format

Ryunosuke Sato edited this page Feb 24, 2021 · 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.

ActiveJob Middleware Format

If writing server middleware and have integrated Sidekiq with ActiveJob the format provided for the second argument of call is as follows:

{
  "class": "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
  "wrapped": "SomeWorker",
  "queue": "default",
  "args":[
    {
      "job_class": "SomeWorker",
      "job_id": "b4a577edbccf1d805744efa9",
      "provider_job_id": null,
      "queue_name": "default",
      "priority": null,
      "arguments": ["some",["argument","value"]],
      "executions": 0,
      "locale": "en",
      "attempt_number": 1
    }
  ],
  "retry": true,
  "wait": "0.1",
  "jid": "d774900367dc8b2962b2479c", // Note different JID
  "created_at": 1234567890,
  "locale": "en",
  "enqueued_at": 1234567890,
  "error_message": null,
  "error_class": null,
  "failed_at": null,
  "retry_count": 0,
  "retried_at": null
}

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.

Clone this wiki locally