added job to log queue lengths

This commit is contained in:
Miodec 2023-02-01 02:03:26 +01:00
parent bb39afa753
commit 666522c0b3
2 changed files with 38 additions and 1 deletions

View file

@ -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,
];

View file

@ -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<void> {
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);