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.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Shared PgBoss singleton — kept in its own module to break circular imports
|
||||
* between workert.ts and the worker modules that call getBoss().
|
||||
*/
|
||||
import { PgBoss } from "pg-boss";
|
||||
|
||||
function makePgBossUrl(rawUrl: string): string {
|
||||
try {
|
||||
const u = new URL(rawUrl);
|
||||
// 30-second statement timeout to prevent individual SQL queries from
|
||||
// hanging indefinitely if the DB server stops responding mid-query.
|
||||
u.searchParams.set("options", "-c statement_timeout=30000");
|
||||
return u.toString();
|
||||
} catch {
|
||||
return rawUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export const boss = new PgBoss({
|
||||
connectionString: makePgBossUrl(process.env.DATABASE_URL!),
|
||||
connectionTimeoutMillis: 15_000,
|
||||
});
|
||||
|
||||
boss.on("error", (err) => {
|
||||
console.error("[worker] PgBoss error", err);
|
||||
});
|
||||
|
||||
export function getBoss(): PgBoss {
|
||||
return boss;
|
||||
}
|
||||
Reference in New Issue
Block a user