0
0
NestJSframework~30 mins

Queue events and monitoring in NestJS - Mini Project: Build & Apply

Choose your learning style9 modes available
Queue Events and Monitoring in NestJS
📖 Scenario: You are building a simple task queue system in a NestJS application. You want to track when tasks are added to the queue and when they are completed. This helps you monitor the queue's activity and ensure tasks are processed correctly.
🎯 Goal: Create a NestJS service that manages a queue of tasks. You will add tasks to the queue, track events when tasks are added and completed, and print monitoring messages to the console.
📋 What You'll Learn
Create a queue array to hold task names
Add a configuration variable to count completed tasks
Implement functions to add tasks and mark them as completed with event logs
Print the current queue and completed task count
💡 Why This Matters
🌍 Real World
Monitoring queue events helps teams track task progress and system health in real-time, which is critical for reliable applications.
💼 Career
Understanding queue event handling and monitoring is essential for backend developers and DevOps engineers working with task processing systems.
Progress0 / 4 steps
1
Create the initial queue array
Create a variable called taskQueue and set it to an empty array to hold task names.
NestJS
Need a hint?

Use const taskQueue: string[] = []; to create an empty array for tasks.

2
Add a completed task counter
Create a variable called completedCount and set it to 0 to count completed tasks.
NestJS
Need a hint?

Use let completedCount = 0; to track how many tasks are done.

3
Implement add and complete task functions with event logs
Write a function called addTask that takes a taskName string, adds it to taskQueue, and logs "Task added: ". Write another function called completeTask that removes the first task from taskQueue, increments completedCount, and logs "Task completed: ".
NestJS
Need a hint?

Use taskQueue.push(taskName) to add and taskQueue.shift() to remove the first task. Use console.log to print messages.

4
Print the queue and completed task count
Write two console.log statements: one to print "Current queue:" followed by the taskQueue array, and another to print "Completed tasks:" followed by the completedCount.
NestJS
Need a hint?

Use console.log("Current queue:", taskQueue); and console.log("Completed tasks:", completedCount); to show the status.