auto-lms / src /server /queue /boss.ts
akashdahad's picture
Deploy auto-lms (Next.js + worker + embedded Postgres)
6d6eaef verified
Raw History Blame Contribute Delete
643 Bytes
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<PgBoss> | null = null;
export async function getBoss(): Promise<PgBoss> {
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;
}