feat(jobs): echo worker + CLI bootstrap
Job queue starts only in the CLI gate (not inside createApp), so tests manage their own queue lifecycle. waitForJob() takes a (name, id) pair to match pg-boss v10's getJobById signature. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,18 +6,14 @@ export async function stopBoss() {
|
||||
try { await pool.query('DROP SCHEMA IF EXISTS pgboss CASCADE'); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
export async function waitForJob(id, { timeoutMs = 5_000 } = {}) {
|
||||
export async function waitForJob(name, 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;
|
||||
const j = await boss.getJobById(name, id, { includeArchive: true });
|
||||
if (j && ['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`);
|
||||
throw new Error(`job ${name} ${id} did not finish in ${timeoutMs} ms`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user