Performance: Job options (backoff, attempts, priority)
This concept affects how background jobs are scheduled and retried, impacting server responsiveness and throughput.
await queue.add('email', data, { attempts: 3, backoff: 5000, priority: 1 });
await queue.add('email', data, { attempts: 10, backoff: 0, priority: 1 });
| Pattern | CPU Usage | Memory Usage | Job Throughput | Verdict |
|---|---|---|---|---|
| Immediate retries with no backoff | High spikes | High | Low due to blocking | [X] Bad |
| Retries with backoff and limited attempts | Moderate and stable | Moderate | High and smooth | [OK] Good |
delay option do when adding a job?delay in job optionsdelay option is used to postpone when a job starts running after being added to the queue.attempts controls retries, priority controls order, so they do not delay execution.attempts for retries and delay for postponing in milliseconds.queue.add('job1', data1, { priority: 2 });
queue.add('job2', data2, { priority: 1 });
queue.add('job3', data3, { priority: 3 });queue.add('emailJob', data, { delay: '1000', attempts: 5 });delay expects a number in milliseconds, but here it is a string '1000'.attempts is valid, job name as string is correct, data is present.Pass the test and this pattern moves unknown