0
0
NestJSframework~10 mins

Queue consumers (processors) in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a queue processor using NestJS.

NestJS
import { Processor, [1] } from '@nestjs/bull';

@Processor('email')
export class EmailProcessor {
  // processor methods here
}
Drag options to blanks, or click blank then click option'
AProcess
BInjectQueue
COnQueueCompleted
DQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using @InjectQueue instead of @Process
Confusing @OnQueueCompleted with @Process
2fill in blank
medium

Complete the code to define a method that processes jobs in the queue.

NestJS
@Process('send_email')
async [1](job: Job) {
  // processing logic
}
Drag options to blanks, or click blank then click option'
AhandleJob
BsendEmail
CprocessJob
DonCompleted
Attempts:
3 left
💡 Hint
Common Mistakes
Using lifecycle event names like onCompleted as method name
Using unrelated method names
3fill in blank
hard

Fix the error in the processor method signature to correctly receive the job data.

NestJS
async processJob([1]: Job) {
  console.log(job.data);
}
Drag options to blanks, or click blank then click option'
Adata
Bjob
Cpayload
Dtask
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the parameter data and trying to access job.data
Using unrelated parameter names
4fill in blank
hard

Fill both blanks to import and use the Job type from Bull in the processor.

NestJS
import { Processor, Process } from '@nestjs/bull';
import { [1] } from 'bull';

@Processor('notifications')
export class NotificationProcessor {
  @Process('notify')
  async handleNotification(job: [2]) {
    // handle notification
  }
}
Drag options to blanks, or click blank then click option'
AJob
BQueue
CJobOptions
DWorker
Attempts:
3 left
💡 Hint
Common Mistakes
Importing or using incorrect types like Queue or Worker
Not typing the job parameter
5fill in blank
hard

Fill all three blanks to create a processor that logs job data and marks completion.

NestJS
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}`);
  }
}
Drag options to blanks, or click blank then click option'
AhandleExecute
BJob
ConComplete
DQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types for job parameter
Incorrect method names for processing or completion