File
Blob: src/worker/common/progress.ts
| 1 | import type { CacheContext } from "@/worker/cache"; |
| 2 | import { getLimiter } from "@/worker/git/operations/limits"; |
| 3 | |
| 4 | import { getRepoStub } from "./stub"; |
| 5 | |
| 6 | export interface RepoActivity { |
| 7 | state: "receiving" | "compacting"; |
| 8 | startedAt?: number; |
| 9 | expiresAt?: number; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Fetch repository activity for banner rendering. |
| 14 | * Idle repos return null so callers can keep the existing "render nothing" |
| 15 | * behavior without interpreting state as correctness data. |
| 16 | * |
| 17 | * Pass `cacheCtx` so the DO RPC shares the per-request subrequest limiter. |
| 18 | */ |
| 19 | export async function getRepoActivity( |
| 20 | env: Env, |
| 21 | repoId: string, |
| 22 | cacheCtx?: CacheContext |
| 23 | ): Promise<RepoActivity | null> { |
| 24 | try { |
| 25 | const stub = getRepoStub(env, repoId); |
| 26 | const limiter = getLimiter(cacheCtx); |
| 27 | return await limiter.run("do:get-repo-activity", () => stub.getRepoActivity()); |
| 28 | } catch { |
| 29 | return null; |
| 30 | } |
| 31 | } |