File
Blob: src/worker/api/private/reconciliation.ts
| 1 | import type { ProjectId } from "@/contracts"; |
| 2 | import type { AppContext } from "@/worker/hono"; |
| 3 | import { createLogger } from "@/worker/services"; |
| 4 | |
| 5 | const logger = createLogger("worker.project-reconciliation"); |
| 6 | |
| 7 | const getProjectStub = (env: AppContext["env"], projectId: ProjectId) => env.PROJECT_DO.getByName(projectId); |
| 8 | |
| 9 | export const queueProjectReconciliation = (c: AppContext, projectId: ProjectId, trigger: string): void => { |
| 10 | // ProjectDO owns D1 sync and queue dispatch, but read/write HTTP handlers are the reliable place where |
| 11 | // we have a Worker execution context that can nudge reconciliation without blocking the response path. |
| 12 | const stub = getProjectStub(c.env, projectId); |
| 13 | c.executionCtx.waitUntil( |
| 14 | stub.kickReconciliation().catch((error) => { |
| 15 | logger.warn("project_reconciliation_kick_failed", { |
| 16 | projectId, |
| 17 | trigger, |
| 18 | error: error instanceof Error ? error.message : String(error), |
| 19 | }); |
| 20 | }), |
| 21 | ); |
| 22 | }; |