Complete the code to import the BullModule for a queue named 'email'.
import { BullModule } from '@nestjs/bull'; @Module({ imports: [BullModule.[1]({ name: 'email' })], }) export class AppModule {}
The forFeature method registers a queue named 'email' in a module.
Complete the code to listen for the 'completed' event on a queue.
import { OnQueueEvent } from '@nestjs/bull'; @Processor('email') export class EmailProcessor { @OnQueueEvent('completed') handleCompleted(job: Job, result: any) { console.log(`Job ${job.[1] completed`); } }
The job.id uniquely identifies the completed job.
Fix the error in the event listener method to correctly handle failed jobs.
@OnQueueEvent('failed') handleFailed(job: Job, [1]: Error) { console.error(`Job ${job.id} failed with error:`, error.message); }
The parameter name must match the variable used inside the method, which is error.
Fill both blanks to create a dictionary of job counts filtered by status.
async getJobCounts() {
const counts = await this.queue.getJobCounts('[1]', '[2]');
return counts;
}The method filters job counts by 'waiting' and 'failed' statuses.
Fill all three blanks to create a filtered dictionary of jobs with their IDs and timestamps.
async getFilteredJobs() {
const jobs = await this.queue.getJobs(['[1]', '[2]']);
return jobs.map(job => ({ id: job.[3], timestamp: job.timestamp }));
}The method fetches jobs with statuses 'completed' and 'failed', then maps their IDs and timestamps.
