Skip to content
File

Blob: src/worker/api/private/reconciliation.ts

typescript23 lines
1import type { ProjectId } from "@/contracts";
2import type { AppContext } from "@/worker/hono";
3import { createLogger } from "@/worker/services";
4 
5const logger = createLogger("worker.project-reconciliation");
6 
7const getProjectStub = (env: AppContext["env"], projectId: ProjectId) => env.PROJECT_DO.getByName(projectId);
8 
9export 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};