Bird
Raised Fist0
NestJSframework~20 mins

Queue events and monitoring in NestJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Queue Events and Monitoring Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output when a job is completed in a NestJS queue?
Consider a NestJS queue with an event listener for the 'completed' event. What will be logged when a job with ID 42 completes successfully?
NestJS
queue.on('completed', (job) => {
  console.log(`Job ${job.id} completed with result: ${job.returnvalue}`);
});

queue.add({ task: 'sendEmail' });

// Assume job with ID 42 completes with returnvalue 'Email sent'.
AJob 42 completed
BJob completed with result: Email sent
CJob 42 completed with result: Email sent
DJob completed
Attempts:
2 left
💡 Hint
Look at how the job ID and return value are accessed in the event listener.
🧠 Conceptual
intermediate
1:30remaining
Which event should you listen to for retrying failed jobs in NestJS queues?
You want to retry jobs automatically when they fail in a NestJS queue. Which event is best to listen for to trigger retry logic?
A'failed'
B'waiting'
C'completed'
D'active'
Attempts:
2 left
💡 Hint
Retry logic is triggered when a job does not succeed.
❓ Configuration
advanced
3:00remaining
How to enable detailed queue monitoring with Bull in NestJS?
Which configuration snippet correctly enables the built-in UI dashboard for Bull queue monitoring in a NestJS app?
NestJS
import { BullModule } from '@nestjs/bull';
import { createBullBoard } from '@bull-board/api';
import { BullAdapter } from '@bull-board/api/bullAdapter';
import { ExpressAdapter } from '@bull-board/express';

const serverAdapter = new ExpressAdapter();
createBullBoard({ queues: [new BullAdapter(myQueue)], serverAdapter });

app.use('/admin/queues', serverAdapter.getRouter());
AUse BullModule.forRoot({ monitor: true }) without additional setup
BInstall 'bull-monitor' package and import it in main.ts without further config
CAdd 'monitoring: true' in queue options in BullModule.registerQueue
DUse BullModule.registerQueue({ name: 'myQueue' }) and set up Bull Board with ExpressAdapter as shown
Attempts:
2 left
💡 Hint
Bull Board requires explicit setup with adapters and routes.
❓ Troubleshoot
advanced
2:30remaining
Why does the 'completed' event not fire in a NestJS Bull queue?
You added a listener for the 'completed' event on a Bull queue in NestJS, but it never triggers even though jobs finish successfully. What is the most likely cause?
ARedis server is down
BThe event listener is added after jobs are processed
CThe queue processor function does not return a value
DThe queue is not registered with BullModule
Attempts:
2 left
💡 Hint
Check the timing of when the event listener is added relative to job processing.
✅ Best Practice
expert
3:00remaining
What is the best practice for monitoring job failures in production NestJS queues?
In a production NestJS app using Bull queues, what is the best practice to monitor and alert on job failures?
AUse the 'failed' event to send alerts to an external monitoring service like Sentry or Datadog
BLog failures to console and check logs manually
CIgnore failures and rely on retries only
DRestart the queue worker process on any failure
Attempts:
2 left
💡 Hint
Automated alerting helps catch issues early.

Practice

(1/5)
1. What is the main purpose of using @OnQueueEvent decorators in NestJS queues?
easy
A. To delete jobs from the queue manually
B. To listen and react to specific queue events like job completion or failure
C. To configure the queue's concurrency settings
D. To create new queues dynamically at runtime

Solution

  1. Step 1: Understand the role of @OnQueueEvent

    This decorator is used to listen for events emitted by the queue, such as when a job completes or fails.
  2. Step 2: Identify what @OnQueueEvent does not do

    It does not create queues, configure concurrency, or delete jobs manually; it only listens to events.
  3. Final Answer:

    To listen and react to specific queue events like job completion or failure -> Option B
  4. Quick Check:

    @OnQueueEvent listens to events [OK]
Hint: Remember: @OnQueueEvent listens to queue events only [OK]
Common Mistakes:
  • Thinking it creates or deletes queues
  • Confusing event listening with queue configuration
  • Assuming it manages job concurrency
2. Which of the following is the correct syntax to listen for a 'completed' event in a NestJS queue using @OnQueueEvent?
easy
A. @OnQueueEvent('done') handleDone(job: Job) { // handle job completion }
B. @OnQueueEvent('complete') handleComplete(job: Job) { // handle job completion }
C. @OnQueueEvent('completed') handleCompleted(job: Job) { // handle job completion }
D. @OnQueueEvent('finished') handleFinished(job: Job) { // handle job completion }

Solution

  1. Step 1: Recall the exact event name for job completion

    The official event name emitted by NestJS queues for job completion is 'completed'.
  2. Step 2: Match the syntax with the correct event name

    The syntax must use @OnQueueEvent('completed') to listen properly.
  3. Final Answer:

    @OnQueueEvent('completed')\nhandleCompleted(job: Job) {\n // handle job completion\n} -> Option C
  4. Quick Check:

    Event name is 'completed' exactly [OK]
Hint: Use exact event names like 'completed' with @OnQueueEvent [OK]
Common Mistakes:
  • Using incorrect event names like 'complete' or 'done'
  • Misspelling the decorator syntax
  • Not passing the event name as a string
3. Given the following code snippet, what will be logged when a job fails in the queue?
@OnQueueEvent('failed')
handleFailed(job: Job, error: Error) {
  console.log(`Job ${job.id} failed with error: ${error.message}`);
}
medium
A. Job <job_id> failed with error: <error_message>
B. Job failed with error: <error_message>
C. Job <job_id> completed successfully
D. Error occurred but no job info logged

Solution

  1. Step 1: Analyze the event and handler parameters

    The handler listens to the 'failed' event and receives the job and error objects.
  2. Step 2: Understand the console.log output

    The log prints the job's id and the error's message in the format: "Job failed with error: ".
  3. Final Answer:

    Job <job_id> failed with error: <error_message> -> Option A
  4. Quick Check:

    Failed event logs job id and error message [OK]
Hint: Failed event handlers get job and error objects [OK]
Common Mistakes:
  • Ignoring job id in the log message
  • Confusing 'failed' with 'completed' event
  • Logging incomplete error information
4. You wrote this event listener but it never triggers:
@OnQueueEvent('completed')
handleCompleted() {
  console.log('Job done');
}
What is the likely problem?
medium
A. The event name 'completed' is incorrect
B. You must call the handler manually after job completion
C. The method name must be 'onCompleted' instead of 'handleCompleted'
D. The handler is missing the job parameter to receive event data

Solution

  1. Step 1: Check the event handler signature

    Event handlers for 'completed' receive the job object as a parameter, but this method has none.
  2. Step 2: Understand why missing parameters cause no trigger

    Without the expected parameter, NestJS cannot properly call the handler, so it never triggers.
  3. Final Answer:

    The handler is missing the job parameter to receive event data -> Option D
  4. Quick Check:

    Event handlers need correct parameters [OK]
Hint: Always include expected parameters in event handlers [OK]
Common Mistakes:
  • Omitting parameters in event handlers
  • Changing event names incorrectly
  • Thinking handlers must be called manually
5. You want to monitor a NestJS queue to log when jobs are added, completed, or failed. Which combination of event listeners should you implement to cover these events effectively?
hard
A. Use @OnQueueEvent('waiting'), @OnQueueEvent('completed'), and @OnQueueEvent('failed')
B. Use @OnQueueEvent('added'), @OnQueueEvent('done'), and @OnQueueEvent('error')
C. Use @OnQueueEvent('start'), @OnQueueEvent('finish'), and @OnQueueEvent('fail')
D. Use @OnQueueEvent('enqueue'), @OnQueueEvent('success'), and @OnQueueEvent('failure')

Solution

  1. Step 1: Identify correct event names for job lifecycle

    In NestJS queues, 'waiting' is emitted when a job is added, 'completed' when done, and 'failed' on failure.
  2. Step 2: Verify the other options' event names

    Other options use incorrect or non-existent event names like 'added', 'done', 'error', 'start', 'finish', 'fail', 'enqueue', 'success', 'failure'.
  3. Final Answer:

    Use @OnQueueEvent('waiting'), @OnQueueEvent('completed'), and @OnQueueEvent('failed') -> Option A
  4. Quick Check:

    Correct event names: waiting, completed, failed [OK]
Hint: Use official event names: waiting, completed, failed [OK]
Common Mistakes:
  • Using wrong event names not recognized by NestJS
  • Missing the 'waiting' event for job addition
  • Confusing 'failed' with 'fail' or 'error'
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard