Skip to content

Commit 9c5dbb2

Browse files
committed
feat: monitor stuck queues
1 parent 5e7da34 commit 9c5dbb2

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

apps/backend/src/api/api.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { McpService } from '@gitroom/nestjs-libraries/mcp/mcp.service';
3535
import { McpController } from '@gitroom/backend/api/routes/mcp.controller';
3636
import { SetsController } from '@gitroom/backend/api/routes/sets.controller';
3737
import { ThirdPartyController } from '@gitroom/backend/api/routes/third-party.controller';
38+
import { MonitorController } from '@gitroom/backend/api/routes/monitor.controller';
3839

3940
const authenticatedController = [
4041
UsersController,
@@ -63,6 +64,7 @@ const authenticatedController = [
6364
AuthController,
6465
PublicController,
6566
McpController,
67+
MonitorController,
6668
...authenticatedController,
6769
],
6870
providers: [
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Controller, Get, Param } from '@nestjs/common';
2+
import { ApiTags } from '@nestjs/swagger';
3+
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client';
4+
5+
@ApiTags('Monitor')
6+
@Controller('/monitor')
7+
export class MonitorController {
8+
constructor(private _workerServiceProducer: BullMqClient) {}
9+
10+
@Get('/queue/:name')
11+
getMessagesGroup(@Param('name') name: string) {
12+
return this._workerServiceProducer.checkForStuckWaitingJobs(name);
13+
}
14+
}

libraries/nestjs-libraries/src/bull-mq-transport-new/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ export class BullMqClient extends ClientProxy {
7777
);
7878
}
7979

80+
async checkForStuckWaitingJobs(queueName: string) {
81+
const queue = this.getQueue(queueName);
82+
const getJobs = await queue.getJobs('waiting' as const);
83+
const now = Date.now();
84+
const thresholdMs = 60 * 60 * 1000;
85+
return {
86+
valid: !getJobs.some((job) => {
87+
const age = now - job.timestamp;
88+
return age > thresholdMs;
89+
}),
90+
};
91+
}
92+
8093
async dispatchEvent(packet: ReadPacket<any>): Promise<any> {
8194
console.log('event to dispatch: ', packet);
8295
const queue = this.getQueue(packet.pattern);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"packageManager": "[email protected]",
1313
"scripts": {
14-
"dev": "pnpm run --filter ./apps/extension --filter ./apps/workers --filter ./apps/backend --filter ./apps/frontend --parallel dev",
14+
"dev": "pnpm run --filter ./apps/extension --filter ./apps/backend --filter ./apps/frontend --parallel dev",
1515
"pm2": "pnpm dlx concurrently \"pnpm run pm2-run\" \"pnpm run entryfile\"",
1616
"entryfile": "./entrypoint.sh",
1717
"publish-sdk": "pnpm run --filter ./apps/sdk publish",

0 commit comments

Comments
 (0)