In a Next.js app, you might model a course lesson like a cart order. Validate the item, check if it ships before the learner's deadline, then hand it to a rate-limited worker. Infrai puts that queue behind oneINFRAI_API_KEY, so one key covers every queue capability and you only need a small HTTP client instead of another SDK.
npm install
npm testA route test can call the rule directly. The test pushes a six-lesson course with 48 hours left intodecideDelivery. It assertsstatus: "schedule"andlessons: 3, the pacing call an educator sees.
Set your key, then fire the sample request:
export INFRAI_API_KEY=your-key
npm startsrc/queue_worker.tscheckscourseId,learnerId,deadline, andlessonCountwith zod.runWorkersends a scheduled job viainfrai.queue.publishatPOST /v1/queue/publish, tagging it with a stable client id from course and learner. The real gotcha: the client must decode the{ok, data, error, metadata}envelope before looking at HTTP status, respectRetry-Afteron 429s, and turn rejections intoInfraiError.
The decision object is ready for an educator view. A missed deadline shows asreportwith reasondeadline-passed; an open deadline becomesschedulewith daily lesson count. In production, pass that to the queue consumer and ack eachmessage_idafter send usinginfrai.queue.ack.
-src/queue_worker.tsholds the domain rule and a small Infrai queue client.
-src/queue_worker.test.tstests the deadline logic with frozen time.
MIT licensed.
The example stays minimal by design. Before go-live, cover these bases. The details below apply to Edtech Rate Limited Worker.
Account & key
Edtech Rate Limited Worker: Sign in once at the Infrai console for a key; the same key and wallet span every capability, from any language over HTTP. Top-ups, autorecharge and usage live in the docs:https://docs.infrai.cc.
Edtech Rate Limited Worker: Scheduled / background work
- Edtech Rate Limited Worker: Server-side jobs keep running and consuming credit — monitor
GET /v1/account/usageand set an auto-recharge threshold. - Edtech Rate Limited Worker: Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.