Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using forRoot instead of forFeature
Trying to use a method that doesn't exist like createQueue
✗ Incorrect
The forFeature method registers a queue named 'email' in a module.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using job.name which may not exist
Using job.status which is not a property
✗ Incorrect
The job.id uniquely identifies the completed job.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the one used inside the method
Not matching the error parameter name
✗ Incorrect
The parameter name must match the variable used inside the method, which is error.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using statuses that are not valid keys for getJobCounts
Mixing up completed and failed statuses
✗ Incorrect
The method filters job counts by 'waiting' and 'failed' statuses.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid job status strings
Using wrong property name for job ID
✗ Incorrect
The method fetches jobs with statuses 'completed' and 'failed', then maps their IDs and timestamps.