Skip to content

Job Management

Monque serves a comprehensive set of APIs for managing jobs throughout their lifecycle.

MethodDescription
cancelJob()Cancel a single job
retryJob()Retry a job
rescheduleJob()Reschedule a job
deleteJob()Delete a job
cancelJobs()Bulk cancel
retryJobs()Bulk retry
deleteJobs()Bulk delete
getJobsWithCursor()Paginated list
getQueueStats()Queue statistics

Manage individual jobs using their unique ID.

Use cancelJob() to prevent a pending or scheduled job from running.

const job = await monque.cancelJob('job-id');
  • Effect: Status becomes cancelled.
  • Event: Emits job:cancelled.
  • Constraint: Cannot cancel processing, completed, or failed jobs (unless they return to pending).

Use retryJob() to retry a failed or cancelled job immediately.

const job = await monque.retryJob('job-id');
  • Effect: Status becomes pending, nextRunAt set to now, failure count reset.
  • Event: Emits job:retried.

Use rescheduleJob() to change the execution time of a pending job.

const nextHour = new Date(Date.now() + 3600000);
const job = await monque.rescheduleJob('job-id', nextHour);

Use deleteJob() to permanently remove a job from the queue.

const success = await monque.deleteJob('job-id');
  • Effect: Document is removed from MongoDB.
  • Event: Emits job:deleted.

Perform operations on multiple jobs matching a filter.

Use cancelJobs() to cancel all pending jobs matching a criteria.

const result = await monque.cancelJobs({
  name: 'email-sender',
  status: 'pending'
});

console.log(`Cancelled ${result.count} jobs`);

Use retryJobs() to retry all failed jobs.

const result = await monque.retryJobs({
  status: 'failed'
});

Use deleteJobs() to clean up old jobs.

const result = await monque.deleteJobs({
  status: ['completed', 'cancelled'],
  olderThan: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // 7 days ago
});
  • Effect: Removing matching documents from MongoDB.
  • Event: Emits jobs:deleted with count.

Efficiently iterate through large sets of jobs using getJobsWithCursor().

// First page
const page1 = await monque.getJobsWithCursor({ limit: 50 });

// Next page
if (page1.hasNextPage && page1.cursor) {
  const page2 = await monque.getJobsWithCursor({
    cursor: page1.cursor,
    limit: 50
  });
}

Supports filtering:

const failedEmails = await monque.getJobsWithCursor({
  filter: { name: 'email', status: 'failed' },
  limit: 20
});

Get real-time insights into your queue health using getQueueStats().

const stats = await monque.getQueueStats();

console.log('Pending:', stats.pending);
console.log('Processing:', stats.processing);
console.log('Failed:', stats.failed);

You can also scope statistics to a specific job name:

const emailStats = await monque.getQueueStats({ name: 'email' });