()
| 13 | const FDB_OPTIONAL_COUNT_TIMEOUT_MS = 500; |
| 14 | |
| 15 | async function cclog() { |
| 16 | const logger = _logger.child({ |
| 17 | module: "cclog", |
| 18 | }); |
| 19 | |
| 20 | const concurrencyByTeam = new Map<string, number>(); |
| 21 | const redis = getRedisConnection(); |
| 22 | let cursor = 0; |
| 23 | do { |
| 24 | const result = await redis.scan( |
| 25 | cursor, |
| 26 | "MATCH", |
| 27 | "concurrency-limiter:*", |
| 28 | "COUNT", |
| 29 | 100000, |
| 30 | ); |
| 31 | cursor = parseInt(result[0], 10); |
| 32 | const usable = result[1].filter(x => !x.includes("preview_")); |
| 33 | |
| 34 | logger.info("Stepped", { cursor, usable: usable.length }); |
| 35 | |
| 36 | if (usable.length > 0) { |
| 37 | for (const x of usable) { |
| 38 | const concurrency = await redis.zrangebyscore(x, Date.now(), Infinity); |
| 39 | const teamId = x.split(":")[1]; |
| 40 | concurrencyByTeam.set( |
| 41 | teamId, |
| 42 | (concurrencyByTeam.get(teamId) ?? 0) + concurrency.length, |
| 43 | ); |
| 44 | } |
| 45 | } |
| 46 | } while (cursor != 0); |
| 47 | |
| 48 | if (fdbQueueEnabled()) { |
| 49 | try { |
| 50 | if (await nuqFdbHealthCheck(FDB_OPTIONAL_COUNT_TIMEOUT_MS)) { |
| 51 | const fdbCounts = await withFdbTimeout( |
| 52 | scrapeQueueFdb.getTeamActiveCounts(), |
| 53 | FDB_OPTIONAL_COUNT_TIMEOUT_MS, |
| 54 | ); |
| 55 | for (const [teamId, concurrency] of fdbCounts) { |
| 56 | concurrencyByTeam.set( |
| 57 | teamId, |
| 58 | (concurrencyByTeam.get(teamId) ?? 0) + concurrency, |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | } catch (e) { |
| 63 | logger.warn("Error reading FDB concurrency", { error: e }); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | const at = new Date(); |
| 68 | const entries = Array.from(concurrencyByTeam.entries()).map( |
| 69 | ([team_id, concurrency]) => ({ |
| 70 | team_id, |
| 71 | concurrency, |
| 72 | created_at: at.toISOString(), |
no test coverage detected
searching dependent graphs…