0
0
NestJSframework~10 mins

Queue events and monitoring 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 import the BullModule for a queue named 'email'.

NestJS
import { BullModule } from '@nestjs/bull';

@Module({
  imports: [BullModule.[1]({ name: 'email' })],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
AforRoot
BforFeature
CregisterQueue
DcreateQueue
Attempts:
3 left
💡 Hint
Common Mistakes
Using forRoot instead of forFeature
Trying to use a method that doesn't exist like createQueue
2fill in blank
medium

Complete the code to listen for the 'completed' event on a queue.

NestJS
import { OnQueueEvent } from '@nestjs/bull';

@Processor('email')
export class EmailProcessor {
  @OnQueueEvent('completed')
  handleCompleted(job: Job, result: any) {
    console.log(`Job ${job.[1] completed`);
  }
}
Drag options to blanks, or click blank then click option'
Aid
Bname
Cstatus
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using job.name which may not exist
Using job.status which is not a property
3fill in blank
hard

Fix the error in the event listener method to correctly handle failed jobs.

NestJS
@OnQueueEvent('failed')
handleFailed(job: Job, [1]: Error) {
  console.error(`Job ${job.id} failed with error:`, error.message);
}
Drag options to blanks, or click blank then click option'
Aerr
Bexception
Cerror
Dfail
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the one used inside the method
Not matching the error parameter name
4fill in blank
hard

Fill both blanks to create a dictionary of job counts filtered by status.

NestJS
async getJobCounts() {
  const counts = await this.queue.getJobCounts('[1]', '[2]');
  return counts;
}
Drag options to blanks, or click blank then click option'
Awaiting
Bcompleted
Cfailed
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using statuses that are not valid keys for getJobCounts
Mixing up completed and failed statuses
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of jobs with their IDs and timestamps.

NestJS
async getFilteredJobs() {
  const jobs = await this.queue.getJobs(['[1]', '[2]']);
  return jobs.map(job => ({ id: job.[3], timestamp: job.timestamp }));
}
Drag options to blanks, or click blank then click option'
Acompleted
Bfailed
Cid
Dwaiting
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid job status strings
Using wrong property name for job ID