0
0
NestJSframework~20 mins

Bull queue integration in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bull Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a job is added to a Bull queue in NestJS?
Consider a NestJS service that adds a job to a Bull queue using this.queue.add('email', { userId: 123 }). What is the immediate behavior after this call?
NestJS
import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull';

@Injectable()
export class EmailService {
  constructor(@InjectQueue('email') private readonly queue: Queue) {}

  async sendWelcomeEmail(userId: number) {
    await this.queue.add('sendEmail', { userId });
  }
}
AThe job is stored but requires manual triggering to start processing.
BThe job is immediately processed synchronously within the same method call.
CThe job is discarded if no worker is listening on the queue.
DThe job is added to the queue and processed asynchronously by a separate worker.
Attempts:
2 left
💡 Hint
Think about how queues work to handle tasks in the background.
📝 Syntax
intermediate
2:00remaining
Which code snippet correctly defines a Bull queue processor in NestJS?
You want to create a processor that handles jobs from the 'email' queue. Which option shows the correct way to define this processor?
A
@Processor('email')
export class EmailProcessor {
  @Job('sendEmail')
  async handleSendEmail(job: Job) {
    // process job
  }
}
B
@Processor('email')
export class EmailProcessor {
  @Process('sendEmail')
  async handleSendEmail(job: Job) {
    // process job
  }
}
C
@Queue('email')
export class EmailProcessor {
  @Process('sendEmail')
  async handleSendEmail(job: Job) {
    // process job
  }
}
D
@Processor('email')
export class EmailProcessor {
  @ProcessQueue('sendEmail')
  async handleSendEmail(job: Job) {
    // process job
  }
}
Attempts:
2 left
💡 Hint
Look for the decorator that marks a class as a queue processor and the method decorator for job types.
state_output
advanced
2:00remaining
What is the state of a Bull job after successful completion?
After a job is processed successfully by a Bull queue worker in NestJS, what is the job's state when you check it using job.getState()?
A"completed"
B"active"
C"failed"
D"waiting"
Attempts:
2 left
💡 Hint
Think about the lifecycle states of a job in Bull after finishing without errors.
🔧 Debug
advanced
2:00remaining
Why does this Bull queue processor never process jobs?
Given this NestJS Bull processor code, why are jobs never processed?
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';

@Processor('email')
export class EmailProcessor {
  @Process('sendEmail')
  async handleSendEmail() {
    console.log('Processing email job');
  }
}
AThe @Process decorator is used incorrectly; it should be @Job.
BThe queue name 'email' does not match the job name 'sendEmail'.
CThe handler method is missing the job parameter, so it never runs correctly.
DThe processor class is missing the @InjectQueue decorator.
Attempts:
2 left
💡 Hint
Check the method signature for required parameters.
🧠 Conceptual
expert
2:00remaining
How does Bull queue handle job retries in NestJS?
You want a job to retry automatically up to 3 times if it fails. Which configuration option achieves this behavior when adding a job to a Bull queue?
Athis.queue.add('sendEmail', data, { attempts: 3 })
Bthis.queue.add('sendEmail', data, { retry: 3 })
Cthis.queue.add('sendEmail', data, { maxRetries: 3 })
Dthis.queue.add('sendEmail', data, { retries: 3 })
Attempts:
2 left
💡 Hint
Look for the official Bull option name for retry attempts.