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:
root
2026-06-01 03:28:06 +10:00
parent 17a13dddb8
commit 53ffd705c4
5 changed files with 56 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ import express from 'express';
import { pool } from './lib/db/pool.js';
import { log } from './lib/log.js';
import { mountApi } from './lib/api/index.js';
import * as queue from './lib/jobs/queue.js';
import { registerWorkers } from './lib/jobs/index.js';
const VERSION = '2.0.0-alpha.2';
@@ -36,5 +38,17 @@ export function createApp() {
if (import.meta.url === `file://${process.argv[1]}`) {
const port = process.env.PORT || 3000;
createApp().listen(port, () => log.info({ port }, 'void-server listening'));
const app = createApp();
queue.start()
.then(registerWorkers)
.then(() => log.info('job queue ready'))
.catch(err => log.error({ err }, 'queue boot failed'));
app.listen(port, () => log.info({ port }, 'void-server listening'));
for (const sig of ['SIGTERM', 'SIGINT']) {
process.on(sig, async () => {
log.info({ sig }, 'shutting down');
try { await queue.stop(); } catch { /* */ }
process.exit(0);
});
}
}