Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

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

Gergő Móricz3e736f1e0d38
diff --git a/apps/api/src/controllers/v0/admin/cclog.ts b/apps/api/src/controllers/v0/admin/cclog.ts
new file mode 100644
index 000000000..f96542856
--- /dev/null
+++ b/apps/api/src/controllers/v0/admin/cclog.ts
@@ -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",
+ });
+ }
+}
diff --git a/apps/api/src/routes/admin.ts b/apps/api/src/routes/admin.ts
index 1901c6f2e..275454860 100644
--- a/apps/api/src/routes/admin.ts
+++ b/apps/api/src/routes/admin.ts
@@ -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),
+);