Skip to main content

Overview

Jobs can include a priority option to affect processing order. Using priorities, job processing order is determined by the specified priority value instead of following FIFO or LIFO patterns.
Adding prioritized jobs is slower than regular jobs, with O(log(n)) complexity relative to the number of jobs in the prioritized set.

Priority Values

From src/classes/job.ts:47:
Priorities range from 1 to 2,097,152, where lower numbers have higher priority.
Jobs without a priority assigned get the highest priority (priority 0) and are processed before jobs with explicit priorities.

Basic Usage

If multiple jobs have the same priority value, they are processed in FIFO (First-In, First-Out) order.

Change Priority

You can change a job’s priority after insertion using the changePriority method:
From src/classes/job.ts:1059:

Change Priority with LIFO

You can also combine priority changes with LIFO ordering:

Get Prioritized Jobs

Prioritized is a separate state. Use getJobs or getPrioritized to retrieve them:

Get Counts per Priority

Retrieve the count of jobs for specific priority values:
This method returns:
  • Jobs in prioritized status (priorities > 0)
  • Jobs in waiting status (priority 0)

Job Options Interface

From src/interfaces/base-job-options.ts:13:

Priority Validation

From src/classes/job.ts:1597:
Priority values must be:
  • Integers (no decimals)
  • Between 0 and 2,097,152

Use Cases

Process VIP customer orders before regular customers:
Process critical alerts before warnings:
Adjust priority based on business logic:

Performance Considerations

Complexity

O(log(n)) for adding prioritized jobs vs O(1) for regular jobs

Use Sparingly

Only use priorities when necessary for your use case

Batch Operations

Consider batching jobs of the same priority to reduce overhead

Monitor Performance

Track metrics to ensure priorities don’t create bottlenecks

Read More

Faster Priority Jobs

Blog post about priority job performance improvements

Change Priority API

changePriority API Reference

Get Prioritized API

getPrioritized API Reference

Counts per Priority

getCountsPerPriority API Reference