Commit data and jobs together
Workers see a job once the transaction that enqueued it commits, and never when it rolls back.
Enqueue work in the transaction that writes your data, share typed task definitions with your workers, and control retries and repeated updates.
Enqueue a job in the transaction that writes its data:
await sql.begin(async tx => {
await tx`update product set price = ${price} where id = ${productId}`
await createJobs(tx).enqueue(indexProductTask, { productId })
})kern-jobs works with your PostgreSQL client: postgres.js, node-postgres, Orchid ORM, kern-orm, kern-db, or another client that runs SQL text with parameters. See Database Clients and Transactions to enqueue in the transactions of each of them.
kern-jobs is part of Kern, a family of PostgreSQL libraries for TypeScript, and integrates with kern-orm and kern-db when your application uses them.