0
0
NestJSframework~20 mins

Queue consumers (processors) in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Queue Mastery in NestJS
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a NestJS queue consumer throws an error?

Consider a NestJS queue consumer that processes jobs. What is the default behavior if the consumer function throws an error during job processing?

NestJS
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';

@Processor('email')
export class EmailProcessor {
  @Process('send')
  async handleSendEmail(job: Job) {
    throw new Error('Failed to send email');
  }
}
AThe job is marked as failed and retried automatically if retry options are set.
BThe job is silently ignored and removed from the queue.
CThe entire queue stops processing further jobs until the error is fixed.
DThe job is marked as completed despite the error.
Attempts:
2 left
💡 Hint

Think about how Bull handles job failures and retries by default.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a NestJS queue processor for a 'notifications' queue?

Choose the correct code snippet that defines a NestJS queue processor for a queue named 'notifications'.

A
import { Processor, Process } from '@nestjs/bull';

@Processor('notifications')
export class NotificationsProcessor {
  @Process('send')
  async handleSend(job: Job) {
    // process job
  }
}
B
import { Processor, Process } from '@nestjs/bull';

@Processor('notifications')
export class NotificationsProcessor {
  @Process()
  async handle(job: Job) {
    // process job
  }
}
C
import { Processor, Process } from '@nestjs/bull';

@Processor()
export class NotificationsProcessor {
  @Process('notifications')
  async handle(job: Job) {
    // process job
  }
}
D
import { Processor, Process } from '@nestjs/bull';

@Processor('notifications')
export class NotificationsProcessor {
  @Process('notifications')
  async handle(job: Job) {
    // process job
  }
}
Attempts:
2 left
💡 Hint

The @Processor decorator takes the queue name. The @Process decorator takes the job name.

state_output
advanced
2:00remaining
What is the value of job.attemptsMade after 2 failed retries?

Given a NestJS queue job configured with 3 attempts, what will be the value of job.attemptsMade inside the processor when the job is being retried for the third time?

NestJS
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';

@Processor('tasks')
export class TasksProcessor {
  @Process('run')
  async handleRun(job: Job) {
    console.log(job.attemptsMade);
    throw new Error('Fail');
  }
}

// Job options: { attempts: 3 }
A1
B3
C2
D0
Attempts:
2 left
💡 Hint

Remember that attemptsMade counts how many times the job has been tried before the current attempt.

🔧 Debug
advanced
2:00remaining
Why does this NestJS queue consumer never process jobs?

Review the following NestJS queue consumer code. Why does it never process any jobs?

NestJS
import { Processor, Process } from '@nestjs/bull';
import { Job } from 'bull';

@Processor('orders')
export class OrdersProcessor {
  @Process('')
  async handleOrder(job: Job) {
    console.log('Processing order', job.id);
  }
}
AThe Job type is imported incorrectly.
BThe @Process decorator has an empty string, so it does not match any job name.
CThe @Processor decorator is missing the queue name.
DThe handleOrder method is not async.
Attempts:
2 left
💡 Hint

Check the @Process decorator argument and how job names are matched.

🧠 Conceptual
expert
2:00remaining
Which statement about NestJS queue processors and concurrency is true?

In NestJS using Bull queues, which statement about concurrency in queue processors is correct?

AConcurrency is automatically handled by Bull and cannot be configured in NestJS.
BConcurrency is controlled only by the number of queue processors registered, not by any decorator option.
CNestJS queue processors process jobs strictly one at a time, concurrency is not supported.
DSetting concurrency in @Process decorator allows multiple jobs of the same type to be processed in parallel within the same processor instance.
Attempts:
2 left
💡 Hint

Think about how Bull and NestJS allow parallel job processing.