Skip to main content
A job includes all data needed to perform its execution, as well as metadata about its current state and execution history.

job.data

The data object that was passed to Queue#add() when creating the job. This is the primary payload used to perform the job.
const job = await queue.add({ email: '[email protected]', userId: 123 });

console.log(job.data);
// { email: '[email protected]', userId: 123 }

job.id

The unique identifier for the job. By default, this is an auto-incrementing integer, but can be customized using the jobId option when adding a job.
const job = await queue.add('email', data, { jobId: 'unique-email-123' });

console.log(job.id); // 'unique-email-123'

job.opts

The job options that were specified when the job was created.
job.opts
JobOpts
Configuration options for the job
const job = await queue.add('email', data, {
  attempts: 3,
  backoff: { type: 'exponential', delay: 1000 },
  removeOnComplete: true
});

console.log(job.opts.attempts); // 3
console.log(job.opts.backoff); // { type: 'exponential', delay: 1000 }

job.attemptsMade

The number of failed attempts that have been made for this job.
job.attemptsMade
number
Number of failed attempts
queue.process(async (job) => {
  console.log(`Attempt ${job.attemptsMade + 1} of ${job.opts.attempts}`);
  
  if (job.attemptsMade > 0) {
    console.log('This is a retry');
  }
  
  // Process the job
});

job.finishedOn

Unix timestamp (in milliseconds) when the job was completed or finally failed after all attempts.
job.finishedOn
number
Unix timestamp in milliseconds
const job = await queue.getJob(jobId);

if (job.finishedOn) {
  const finishedDate = new Date(job.finishedOn);
  console.log(`Job finished at: ${finishedDate.toISOString()}`);
}

Additional Properties

Jobs also contain other useful properties for tracking state:
  • job.timestamp: When the job was created
  • job.processedOn: When the job was last processed
  • job.failedReason: Error message if the job failed
  • job.stacktrace: Array of stack traces from failed attempts
  • job.returnvalue: The return value from a completed job
  • job.name: The job type name (if provided to Queue#add())

toJSON()

toJSON(): object
Serializes the job to a plain JavaScript object. This is useful for storing or transmitting job data.
json
object
Object containing all job properties:

Serializing Jobs

const job = await queue.add({ user: 'john', action: 'send-email' });
const jobJSON = job.toJSON();

console.log(jobJSON);
// {
//   id: '123',
//   name: '__default__',
//   data: { user: 'john', action: 'send-email' },
//   opts: { attempts: 1, delay: 0, ... },
//   progress: 0,
//   delay: 0,
//   timestamp: 1234567890,
//   attemptsMade: 0,
//   failedReason: null,
//   stacktrace: null,
//   returnvalue: null,
//   finishedOn: null,
//   processedOn: null
// }

Storing Job State

// Save job state to database
const job = await queue.getJob(jobId);
const jobSnapshot = job.toJSON();

await database.save('job_snapshots', {
  jobId: job.id,
  snapshot: jobSnapshot,
  savedAt: new Date()
});

API Response

app.get('/api/jobs/:id', async (req, res) => {
  const job = await queue.getJob(req.params.id);
  
  if (!job) {
    return res.status(404).json({ error: 'Job not found' });
  }
  
  // Return job as JSON
  res.json(job.toJSON());
});

Build docs developers (and LLMs) love