Consider a NestJS queue consumer that processes jobs. What is the default behavior if the consumer function throws an error during job processing?
import { Processor, Process } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('email') export class EmailProcessor { @Process('send') async handleSendEmail(job: Job) { throw new Error('Failed to send email'); } }
Think about how Bull handles job failures and retries by default.
When a job processor throws an error, Bull marks the job as failed. If retry options are configured, Bull will retry the job automatically. Otherwise, the job stays failed.
Choose the correct code snippet that defines a NestJS queue processor for a queue named 'notifications'.
The @Processor decorator takes the queue name. The @Process decorator takes the job name.
The @Processor decorator specifies the queue name. The @Process decorator specifies the job name within that queue. Option A correctly uses @Processor('notifications') and @Process('send').
Given a NestJS queue job configured with 3 attempts, what will be the value of job.attemptsMade inside the processor when the job is being retried for the third time?
import { Processor, Process } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('tasks') export class TasksProcessor { @Process('run') async handleRun(job: Job) { console.log(job.attemptsMade); throw new Error('Fail'); } } // Job options: { attempts: 3 }
Remember that attemptsMade counts how many times the job has been tried before the current attempt.
job.attemptsMade is the number of times the job has been attempted before the current run. On the third attempt, attemptsMade is 2.
Review the following NestJS queue consumer code. Why does it never process any jobs?
import { Processor, Process } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('orders') export class OrdersProcessor { @Process('') async handleOrder(job: Job) { console.log('Processing order', job.id); } }
Check the @Process decorator argument and how job names are matched.
The @Process decorator requires a job name string to match jobs. An empty string means no jobs match, so the processor never runs.
In NestJS using Bull queues, which statement about concurrency in queue processors is correct?
Think about how Bull and NestJS allow parallel job processing.
The @Process decorator accepts a concurrency option that allows multiple jobs of the same type to be processed in parallel by the same processor instance.