feat(concurrency-log): add cclog endpoint (FIR-2067) (#1589)

* feat(concurrency-log): add cclog endpoint

* fix(api/routes/admin): misimport

* more misimports
This commit is contained in:
Gergő Móricz 2025-05-22 23:13:35 +02:00 committed by GitHub
parent fd74299134
commit 3e736f1e0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,57 @@
import { redisConnection } from "../../../services/queue-service";
import { supabase_service } from "../../../services/supabase";
import { logger as _logger } from "../../../lib/logger";
import { Request, Response } from "express";
async function cclog() {
const logger = _logger.child({
module: "cclog",
});
let cursor = 0;
do {
const result = await redisConnection.scan(cursor, "MATCH", "concurrency-limiter:*", "COUNT", 100000);
cursor = parseInt(result[0], 10);
const usable = result[1].filter(x => !x.includes("preview_"));
logger.info("Stepped", { cursor, usable: usable.length });
if (usable.length > 0) {
const entries: {
team_id: string;
concurrency: number;
created_at: Date;
}[] = [];
for (const x of usable) {
const at = new Date();
const concurrency = await redisConnection.zrangebyscore(x, Date.now(), Infinity);
if (concurrency) {
entries.push({
team_id: x.split(":")[1],
concurrency: concurrency.length,
created_at: at,
});
}
}
try {
await supabase_service.from("concurrency_log").insert(entries);
} catch (e) {
logger.error("Error inserting", { error: e });
}
}
} while (cursor != 0);
}
export async function cclogController(req: Request, res: Response) {
try {
await cclog()
res.status(200).json({ ok: true });
} catch (e) {
_logger.error("Error", { module: "cclog", error: e });
res.status(500).json({
message: "Error",
});
}
}

View File

@ -9,6 +9,7 @@ import {
import { wrap } from "./v1";
import { acucCacheClearController } from "../controllers/v0/admin/acuc-cache-clear";
import { checkFireEngine } from "../controllers/v0/admin/check-fire-engine";
import { cclogController } from "../controllers/v0/admin/cclog";
export const adminRouter = express.Router();
@ -43,3 +44,8 @@ adminRouter.get(
`/admin/${process.env.BULL_AUTH_KEY}/feng-check`,
wrap(checkFireEngine),
);
adminRouter.get(
`/admin/${process.env.BULL_AUTH_KEY}/cclog`,
wrap(cclogController),
);