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 + ); } }