Performance: Named jobs
Named jobs affect how background tasks are scheduled and managed, impacting server responsiveness and resource usage.
await this.queue.add('sendEmail', { userId: 1 }, { jobId: 'sendEmail:1' }); await this.queue.add('sendEmail', { userId: 1 }, { jobId: 'sendEmail:1' });
await this.queue.add('sendEmail', { userId: 1 }); await this.queue.add('sendEmail', { userId: 1 });
| Pattern | CPU Usage | Memory Usage | Duplicate Jobs | Verdict |
|---|---|---|---|---|
| Unnamed jobs | High due to duplicates | High due to multiple job data | Yes | [X] Bad |
| Named jobs with unique jobId | Lower by avoiding duplicates | Lower by single job instance | No | [OK] Good |
named jobs in NestJS queues?queue.add(name, data).queue.add with a job name and data correctly.const job = await queue.add('reportGeneration', { userId: 42 });
console.log(job.name);queue.add('reportGeneration', data), the job's name property is set to 'reportGeneration'.job.name will print 'reportGeneration'.queue.add({ name: 'cleanupJob' }, { force: true });queue.add method expects the first argument as a string name, not an object.{ name: 'cleanupJob' } instead of a string, causing a syntax error.'emailNotification' in a queue. Which approach correctly uses named jobs to achieve this?queue.getJobs(['jobName']) which returns jobs with that name.remove() on each job deletes them from the queue.Pass the test and this pattern moves unknown