mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-13 03:59:05 +08:00
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:
parent
fd74299134
commit
3e736f1e0d
57
apps/api/src/controllers/v0/admin/cclog.ts
Normal file
57
apps/api/src/controllers/v0/admin/cclog.ts
Normal 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",
|
||||
});
|
||||
}
|
||||
}
|
@ -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),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user