Jobs & queue
Declare typed jobs (name → payload + handler), then dispatch("name", payload) from anywhere. A worker calls process(envelope): routes to the right handler, with automatic retries on failure. Here three jobs are dispatched then processed — “charge-card” fails once, then succeeds.
Tip
In production, pass appId and jobs push to the SDK queue; a Bun task worker calls jobs.process(). Here an in-memory dispatcher dispatches AND processes in one request for a self-contained demo. maxAttempts controls retries (default 1).
Dispatch the jobs to watch the queue process them.
import { createJobs } from "@bext-stack/framework/jobs";
const jobs = createJobs({
appId: "my-site", // dispatches to the bext SDK queue
jobs: {
sendInvoice: { handler: async (p: { orderId: string }) => { /* … */ } },
chargeCard: { maxAttempts: 3, handler: async (p) => { /* may throw → retried */ } },
},
});
// enqueue from a render / action (typed payload):
await jobs.dispatch("sendInvoice", { orderId: "o1" });
// in a task worker, for each pulled envelope:
const result = await jobs.process(envelope); // routes + retries on failure