From 666522c0b3c23d3b63c814e3681ed344900374e4 Mon Sep 17 00:00:00 2001 From: Miodec Date: Wed, 1 Feb 2023 02:03:26 +0100 Subject: [PATCH] added job to log queue lengths --- backend/src/jobs/index.ts | 8 +++++++- backend/src/jobs/log-queue-sizes.ts | 31 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 backend/src/jobs/log-queue-sizes.ts diff --git a/backend/src/jobs/index.ts b/backend/src/jobs/index.ts index b6a1bdfad..13a821331 100644 --- a/backend/src/jobs/index.ts +++ b/backend/src/jobs/index.ts @@ -1,5 +1,11 @@ import updateLeaderboards from "./update-leaderboards"; import deleteOldLogs from "./delete-old-logs"; import logCollectionSizes from "./log-collection-sizes"; +import logQueueSizes from "./log-queue-sizes"; -export default [updateLeaderboards, deleteOldLogs, logCollectionSizes]; +export default [ + updateLeaderboards, + deleteOldLogs, + logCollectionSizes, + logQueueSizes, +]; diff --git a/backend/src/jobs/log-queue-sizes.ts b/backend/src/jobs/log-queue-sizes.ts new file mode 100644 index 000000000..c1c039461 --- /dev/null +++ b/backend/src/jobs/log-queue-sizes.ts @@ -0,0 +1,31 @@ +import { CronJob } from "cron"; +import Queues from "../queues/index"; +import { setQueueLength } from "../utils/prometheus"; + +const CRON_SCHEDULE = "0 */5 * * * *"; + +async function main(): Promise { + Promise.all( + Queues.map(async (queue) => { + const counts = await queue.getJobCounts(); + + const active = counts.active; + const completed = counts.completed; + const failed = counts.failed; + + const waiting = counts.waiting; + const paused = counts.paused; + const delayed = counts.delayed; + const waitingChildren = counts["waiting-children"]; + + const waitingTotal = waiting + paused + delayed + waitingChildren; + + setQueueLength(queue.queueName, "completed", completed); + setQueueLength(queue.queueName, "active", active); + setQueueLength(queue.queueName, "failed", failed); + setQueueLength(queue.queueName, "waiting", waitingTotal); + }) + ); +} + +export default new CronJob(CRON_SCHEDULE, main);