import { DbClient } from '../prisma/db-client'; /** LISTEN/NOTIFY channels the worker loops wait on, one per outbox. */ export const WAKE_CHANNELS = { domainEvents: 'domain_event', calendarSync: 'calendar_sync', webhookDeliveries: 'webhook_delivery', notificationDeliveries: 'notification_delivery', voiceExtraction: 'voice_extraction', } as const; export type WakeChannel = (typeof WAKE_CHANNELS)[keyof typeof WAKE_CHANNELS]; /** * Wakes the worker loop behind `channel` before its next poll. The payload * is always empty: the loop reads its work from the table, so nothing can * leak through the channel or be slipped in as work. On a transaction * client Postgres sends the notification only on commit - a rolled-back * write wakes nobody. A lost notification only delays work until the poll. */ export async function notifyWorker( db: DbClient, channel: WakeChannel, ): Promise { await db.$executeRaw`SELECT pg_notify(${channel}, '')`; }