mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
added job to log queue lengths
This commit is contained in:
parent
bb39afa753
commit
666522c0b3
2 changed files with 38 additions and 1 deletions
|
@ -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,
|
||||
];
|
||||
|
|
31
backend/src/jobs/log-queue-sizes.ts
Normal file
31
backend/src/jobs/log-queue-sizes.ts
Normal 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);
|
Loading…
Reference in a new issue