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.
export const PRIORITY_LIMIT = 2 ** 21;export class Job { /** * Ranges from 0 (highest priority) to 2 097 152 (lowest priority). Note that * using priorities has a slight impact on performance, * so do not use it if not required. * @defaultValue 0 */ priority = 0;}
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.
interface DefaultJobOptions { /** * Ranges from 0 (highest priority) to 2 097 152 (lowest priority). Note that * using priorities has a slight impact on performance, * so do not use it if not required. * @defaultValue 0 */ priority?: number;}
if (this.opts.priority) { if (Math.trunc(this.opts.priority) !== this.opts.priority) { throw new Error(`Priority should not be float`); } if (this.opts.priority > PRIORITY_LIMIT) { throw new Error(`Priority should be between 0 and ${PRIORITY_LIMIT}`); }}