Overview
Jobs can include apriority option to affect processing order. Using priorities, job processing order is determined by the specified priority value instead of following FIFO or LIFO patterns.
Priority Values
Fromsrc/classes/job.ts:47:
1 to 2,097,152, where lower numbers have higher priority.
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 thechangePriority method:
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. UsegetJobs or getPrioritized to retrieve them:
Get Counts per Priority
Retrieve the count of jobs for specific priority values:- Jobs in
prioritizedstatus (priorities > 0) - Jobs in
waitingstatus (priority 0)
Job Options Interface
Fromsrc/interfaces/base-job-options.ts:13:
Priority Validation
Fromsrc/classes/job.ts:1597:
Use Cases
VIP Customer Processing
VIP Customer Processing
Process VIP customer orders before regular customers:
Severity-Based Alerts
Severity-Based Alerts
Process critical alerts before warnings:
Dynamic Priority
Dynamic Priority
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
