Complete the code to import the module needed for background tasks in NestJS.
import { [1] } from '@nestjs/bull';
The BullModule is used in NestJS to handle background processing with queues.
Complete the code to register a queue named 'email' for background jobs.
BullModule.forRoot({
redis: {
host: 'localhost',
port: 6379,
},
}),
BullModule.registerQueue('[1]'),The queue named 'email' is commonly used for background email sending tasks.
Fix the error in the processor decorator to handle jobs from the 'email' queue.
@Processor('[1]') export class EmailProcessor { @Process() async handleJob(job: Job) { // process job } }
The @Processor('email') decorator tells NestJS to handle jobs from the 'email' queue.
Fill both blanks to add a job to the 'email' queue with data containing user email.
constructor(@InjectQueue('[1]') private emailQueue: Queue) {} async sendEmail(userEmail: string) { await this.emailQueue.add({ [2]: userEmail }); }
The queue injected is 'email', and the job data key is userEmail to hold the email address.
Fill all three blanks to create a background job processor that logs the job data and marks it complete.
@Processor('[1]') export class LoggerProcessor { @Process() async handleLog(job: Job<{ [2]: string }>) { console.log(job.data.[3]); } }
The processor listens to the 'log' queue, the job data key is message, and the console logs job.data.message.