Complete the code to create a queue processor using NestJS.
import { Processor, [1] } from '@nestjs/bull'; @Processor('email') export class EmailProcessor { // processor methods here }
The @Processor decorator is used with the Process decorator to define queue processors in NestJS Bull.
Complete the code to define a method that processes jobs in the queue.
@Process('send_email') async [1](job: Job) { // processing logic }
The method name can be anything, but processJob clearly indicates it processes the job.
Fix the error in the processor method signature to correctly receive the job data.
async processJob([1]: Job) {
console.log(job.data);
}data and trying to access job.dataThe parameter must be named job to access job.data.
Fill both blanks to import and use the Job type from Bull in the processor.
import { Processor, Process } from '@nestjs/bull'; import { [1] } from 'bull'; @Processor('notifications') export class NotificationProcessor { @Process('notify') async handleNotification(job: [2]) { // handle notification } }
The Job type from Bull is imported and used to type the job parameter.
Fill all three blanks to create a processor that logs job data and marks completion.
import { Processor, Process, OnQueueCompleted } from '@nestjs/bull'; import { Job } from 'bull'; @Processor('tasks') export class TaskProcessor { @Process('execute') async [1](job: [2]) { console.log(job.data); } @OnQueueCompleted() async [3](job: Job) { console.log(`Job completed: ${job.id}`); } }
The processor method is named handleExecute, the job parameter is typed Job, and the completion handler is onComplete.