The FIFO type is the standard job processing order in BullMQ. Jobs are processed in the same order as they are inserted into the queue.
The order is preserved independently of the number of processors you have. However, with multiple workers or concurrency greater than 1, jobs may complete in a slightly different order since some jobs take more time to complete than others.
import { Queue } from 'bullmq';const myQueue = new Queue('Paint');// Add a job that will be processed after all othersawait myQueue.add('wall', { color: 'pink' });
In some cases, it’s useful to process jobs in LIFO fashion, where the newest jobs are processed before older ones.
import { Queue } from 'bullmq';const myQueue = new Queue('Paint');// Add a job that will be processed before all othersawait myQueue.add('wall', { color: 'pink' }, { lifo: true });
LIFO jobs bypass the normal queue order. Use this option carefully to avoid starving older jobs.
interface JobsOptions { /** * If true, adds the job to the right of the queue instead of the left * @defaultValue false */ lifo?: boolean; /** * If true, removes the job when it successfully completes */ removeOnComplete?: boolean | number | KeepJobs; /** * If true, removes the job when it fails after all attempts */ removeOnFail?: boolean | number | KeepJobs;}