Files
optima/api/src/api/cw/sync.ts
T
HoloPanio 2eb387811d fix(worker): break circular import by extracting PgBoss singleton
incremental-sync.ts and api/cw/sync.ts imported getBoss() from workert.ts.
When workert.ts (the entry point) dynamically imported incremental-sync.ts,
it triggered a circular module re-evaluation that hung indefinitely.

Extract the PgBoss singleton and getBoss() factory to a new boss-instance.ts
module that neither has top-level async side-effects nor imports from
workert.ts. All consumers (workert.ts, index.ts, incremental-sync.ts,
cw/sync.ts) now import from boss-instance.ts instead.
2026-04-14 00:34:33 +00:00

27 lines
841 B
TypeScript

import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import { getBoss } from "../../boss-instance";
import { WorkerQueue } from "../../modules/workers/queues";
/* POST /v1/cw/sync/full */
export default createRoute(
"post",
["/sync/full"],
async (c) => {
const jobId = await getBoss().send(WorkerQueue.DALPURI_FULL_SYNC, {});
if (!jobId) {
throw new Error("Failed to enqueue dalpuri full sync job");
}
const response = apiResponse.successful(
"Full sync enqueued successfully",
{ jobId }
);
return c.json(response, response.status as ContentfulStatusCode);
},
authMiddleware()
);