import PgBoss from 'pg-boss'; // Single pg-boss instance per process, started lazily. pg-boss manages its own // 'pgboss' schema in the same Postgres database — no Redis required. let bossPromise: Promise | null = null; export async function getBoss(): Promise { if (!bossPromise) { const connectionString = process.env.DATABASE_URL; if (!connectionString) { throw new Error('DATABASE_URL is not set'); } const boss = new PgBoss({ connectionString }); boss.on('error', (err) => console.error('[pg-boss] error', err)); bossPromise = boss.start().then(() => boss); } return bossPromise; }