Repository Public
1import { migrate, sql } from './db.ts';2import { startWorkerLoop } from './jobs.ts';3import { handlers, housekeeping } from './worker.ts';45await migrate();6const stop = startWorkerLoop(handlers);7const keep = async () => { try { await housekeeping(); } catch (e) { console.error(JSON.stringify({ level: 'error', msg: 'housekeeping failed', error: String((e as Error).message) })); } };8void keep();9const timer = setInterval(keep, 10 * 60_000);10console.log(JSON.stringify({ level: 'info', msg: 'worker started', pid: process.pid }));11for (const sig of ['SIGINT', 'SIGTERM'] as const) process.on(sig, () => { void (async () => { clearInterval(timer); await stop(); await sql.end({ timeout: 5 }); process.exit(0); })(); });12