feat(jobs): pg-boss singleton client
Per-name ensureQueue promise dedup so concurrent enqueue+subscribe on the same queue do not race createQueue (Postgres deadlock). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
23
tests/helpers/boss.js
Normal file
23
tests/helpers/boss.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import * as queue from '../../lib/jobs/queue.js';
|
||||
import { pool } from '../../lib/db/pool.js';
|
||||
|
||||
export async function stopBoss() {
|
||||
try { await queue.stop(); } catch { /* ignore */ }
|
||||
try { await pool.query('DROP SCHEMA IF EXISTS pgboss CASCADE'); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
export async function waitForJob(id, { timeoutMs = 5_000 } = {}) {
|
||||
const boss = queue.instance();
|
||||
if (!boss) throw new Error('queue not started');
|
||||
const start = Date.now();
|
||||
while (Date.now() - start < timeoutMs) {
|
||||
const j = await boss.getJobById(id);
|
||||
if (!j) {
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
continue;
|
||||
}
|
||||
if (['completed','failed','cancelled','expired'].includes(j.state)) return j;
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
}
|
||||
throw new Error(`job ${id} did not finish in ${timeoutMs} ms`);
|
||||
}
|
||||
Reference in New Issue
Block a user