Spaces:
Sleeping
Sleeping
Download apps/api/src/controllers/v0/admin/cclog.ts from s-eto-hub/firecrawl-api: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/controllers/v0/admin/cclog.ts
- Command line
-
hf download hf://spaces/s-eto-hub/firecrawl-api/apps/api/src/controllers/v0/admin/cclog.ts
-
curl -L -o cclog.ts https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/controllers/v0/admin/cclog.ts
1.87 kB
| import { getRedisConnection } 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 getRedisConnection().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 getRedisConnection().zrangebyscore( | |
| x, | |
| Date.now(), | |
| Infinity, | |
| ); | |
| if (concurrency) { | |
| entries.push({ | |
| team_id: x.split(":")[1], | |
| concurrency: concurrency.length, | |
| created_at: at, | |
| }); | |
| } | |
| } | |
| try { | |
| const { error } = await supabase_service | |
| .from("concurrency_log") | |
| .insert(entries); | |
| if (error) { | |
| logger.error("Error inserting", { | |
| error, | |
| entryCount: entries.length, | |
| }); | |
| } | |
| } 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", | |
| }); | |
| } | |
| } | |