6const defaultTimeoutMs = 10_000 8export const fetchDeployStatsPerWindow = async (opts: { 13 queryFnc: (db: any, startTs: string, endTs: string | undefined) => Promise<number> 15 const { ep, appConfig, actions = ['apply'], timeoutMs = defaultTimeoutMs, queryFnc } = opts 16 if (!appConfig?.envConf?.dbSecrets) return null 18 let rows = readLedger().filter(r => actions.includes(r.action || '')) 21 rows = rows.filter(r => r.ep === epRel) 24 const applyRows = rows 25 .filter(r => r.ts && r.gitSha) 26 .sort((a, b) => a.ts!.localeCompare(b.ts!)) 29 if (!applyRows.length) return null 34 wrapDbEnv({ appConfig, reuseConn: false }, async ({ db }) => { 36 for (let i = 0; i < applyRows.length; i++) { 37 const row = applyRows[i] 38 const startTs = row.ts! 39 const endTs = i < applyRows.length - 1 ? applyRows[i + 1]!.ts! : undefined 40 const value = await queryFnc(db, startTs, endTs) 41 results.push({ gitSha: row.gitSha!, value }) 43 capturedResults = results 45 new Promise<null>(resolve => setTimeout(() => resolve(null), timeoutMs)), 47 return capturedResults