fix(jobs): log a failed preload report instead of swallowing it

The sweep keeps going when reporting a load failure itself throws, and
now says so on stderr; the error-level guard refuses a silent catch in
src/lib/jobs. The preload test reads the worker source through
readSource with anchors.
This commit is contained in:
Marc-André Bombeck committed 2026-10-25 00:51:32 +02:00
1 parent 2ae23f4ca8
commit cc284c4307
2 files changed
+13 -9

No files matched your search

@@ -7,9 +7,6 @@
* with nobody told at deploy time. The worker now loads every handler once in
* the background after binding and reports each failure by queue name.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Job, PgBoss } from "pg-boss";
@@ -47,6 +44,8 @@ import { emitSignal } from "@/lib/logging/signal";
import { reportWorkerError } from "@/lib/jobs/report-worker-error";
import { reportHandlerLoadFailure } from "@/lib/jobs/run-job";
import { readSource } from "@/__tests__/helpers/source-files";
import type { JobDefinition, JobGroup } from "../define-job";
import {
preloadHandlers,
@@ -156,10 +155,10 @@ describe("preloading the job handlers at worker boot", () => {
});
it("is started by the worker after binding, without holding up the boot", () => {
const source = readFileSync(
join(process.cwd(), "src/lib/jobs/reminder-worker.ts"),
"utf8",
);
const source = readSource("src/lib/jobs/reminder-worker.ts", [
"registry.registerAllJobGroups(",
"void registry.preloadHandlers(bound)",
]);
const register = source.indexOf("registry.registerAllJobGroups(");
const preload = source.indexOf("void registry.preloadHandlers(bound)");
expect(register).toBeGreaterThan(-1);
+7 -2
View File
@@ -208,8 +208,13 @@ export async function preloadHandlers(
failed.push(queue);
try {
await report(queue, error);
} catch {
// The report is the last line of defence; it must not stop the sweep.
} catch (reportError) {
// The report failing must not stop the sweep; say so on stderr.
workerLog(
"error",
`[registry] reporting the load failure of ${queue} failed`,
reportError,
);
}
}
}