feat: monitor stuck queues
This commit is contained in:
parent
5e7da34863
commit
9c5dbb2b4f
|
|
@ -35,6 +35,7 @@ import { McpService } from '@gitroom/nestjs-libraries/mcp/mcp.service';
|
|||
import { McpController } from '@gitroom/backend/api/routes/mcp.controller';
|
||||
import { SetsController } from '@gitroom/backend/api/routes/sets.controller';
|
||||
import { ThirdPartyController } from '@gitroom/backend/api/routes/third-party.controller';
|
||||
import { MonitorController } from '@gitroom/backend/api/routes/monitor.controller';
|
||||
|
||||
const authenticatedController = [
|
||||
UsersController,
|
||||
|
|
@ -63,6 +64,7 @@ const authenticatedController = [
|
|||
AuthController,
|
||||
PublicController,
|
||||
McpController,
|
||||
MonitorController,
|
||||
...authenticatedController,
|
||||
],
|
||||
providers: [
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport-new/client';
|
||||
|
||||
@ApiTags('Monitor')
|
||||
@Controller('/monitor')
|
||||
export class MonitorController {
|
||||
constructor(private _workerServiceProducer: BullMqClient) {}
|
||||
|
||||
@Get('/queue/:name')
|
||||
getMessagesGroup(@Param('name') name: string) {
|
||||
return this._workerServiceProducer.checkForStuckWaitingJobs(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,6 +77,19 @@ export class BullMqClient extends ClientProxy {
|
|||
);
|
||||
}
|
||||
|
||||
async checkForStuckWaitingJobs(queueName: string) {
|
||||
const queue = this.getQueue(queueName);
|
||||
const getJobs = await queue.getJobs('waiting' as const);
|
||||
const now = Date.now();
|
||||
const thresholdMs = 60 * 60 * 1000;
|
||||
return {
|
||||
valid: !getJobs.some((job) => {
|
||||
const age = now - job.timestamp;
|
||||
return age > thresholdMs;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
async dispatchEvent(packet: ReadPacket<any>): Promise<any> {
|
||||
console.log('event to dispatch: ', packet);
|
||||
const queue = this.getQueue(packet.pattern);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
},
|
||||
"packageManager": "pnpm@10.6.1",
|
||||
"scripts": {
|
||||
"dev": "pnpm run --filter ./apps/extension --filter ./apps/workers --filter ./apps/backend --filter ./apps/frontend --parallel dev",
|
||||
"dev": "pnpm run --filter ./apps/extension --filter ./apps/backend --filter ./apps/frontend --parallel dev",
|
||||
"pm2": "pnpm dlx concurrently \"pnpm run pm2-run\" \"pnpm run entryfile\"",
|
||||
"entryfile": "./entrypoint.sh",
|
||||
"publish-sdk": "pnpm run --filter ./apps/sdk publish",
|
||||
|
|
|
|||
Loading…
Reference in New Issue