From a38aa176e58231cce52611e1b8e6f14adec271be Mon Sep 17 00:00:00 2001 From: Nevo David Date: Mon, 21 Jul 2025 16:00:31 +0700 Subject: [PATCH] feat: throw error --- .../src/api/routes/monitor.controller.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/api/routes/monitor.controller.ts b/apps/backend/src/api/routes/monitor.controller.ts index c90fe4b1..6409def7 100644 --- a/apps/backend/src/api/routes/monitor.controller.ts +++ b/apps/backend/src/api/routes/monitor.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Param } from '@nestjs/common'; +import { Controller, Get, HttpException, Param } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client'; @@ -8,7 +8,23 @@ export class MonitorController { constructor(private _workerServiceProducer: BullMqClient) {} @Get('/queue/:name') - getMessagesGroup(@Param('name') name: string) { - return this._workerServiceProducer.checkForStuckWaitingJobs(name); + async getMessagesGroup(@Param('name') name: string) { + const { valid } = + await this._workerServiceProducer.checkForStuckWaitingJobs(name); + + if (valid) { + return { + status: 'success', + message: `Queue ${name} is healthy.`, + }; + } + + throw new HttpException( + { + status: 'error', + message: `Queue ${name} has stuck waiting jobs.`, + }, + 503 + ); } }