Fix pg-boss queue creation before work registration
pg-boss v10 requires explicit queue creation via `createQueue()` before `schedule()` or `work()` can reference a queue. Without this, the planner crashes on startup in fresh databases (like CI) with "Queue not found". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
32c5fbde8f
commit
f75dd12f59
2 changed files with 13 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ function createMockBoss() {
|
|||
return {
|
||||
start: vi.fn().mockResolvedValue(undefined),
|
||||
stop: vi.fn().mockResolvedValue(undefined),
|
||||
createQueue: vi.fn().mockResolvedValue(undefined),
|
||||
schedule: vi.fn().mockResolvedValue(undefined),
|
||||
work: vi.fn().mockResolvedValue("worker-id"),
|
||||
};
|
||||
|
|
@ -22,6 +23,16 @@ describe("startWorker", () => {
|
|||
expect(boss.start).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("creates queues before registering handlers", async () => {
|
||||
const boss = createMockBoss();
|
||||
const jobs: JobDefinition[] = [{ name: "test-job", handler: vi.fn() }];
|
||||
|
||||
await startWorker(boss as never, jobs);
|
||||
|
||||
expect(boss.createQueue).toHaveBeenCalledWith("test-job");
|
||||
expect(boss.createQueue).toHaveBeenCalledBefore(boss.work);
|
||||
});
|
||||
|
||||
it("registers job handlers", async () => {
|
||||
const boss = createMockBoss();
|
||||
const handler = vi.fn();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ export async function startWorker(
|
|||
await boss.start();
|
||||
|
||||
for (const job of jobs) {
|
||||
await boss.createQueue(job.name);
|
||||
|
||||
if (job.cron) {
|
||||
await boss.schedule(job.name, job.cron, undefined, {
|
||||
retryLimit: job.retryLimit,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue