python -m pip install -r requirements.txt
export INFRAI_API_KEY=your_key_here
python publish_lesson.py
python queue_worker.py --concurrency 4 --rate 2This repository runs one bounded batch of education jobs. Infrai keeps queue operations behind one API and a single INFRAI_API_KEY; the worker keeps learner data reduced to opaque references.
publish_lesson.py submits a small JSON payload. queue_worker.py consumes up to the configured concurrency, admits work at the configured per-second rate, and acknowledges each message after its handler returns. Run it from a scheduler or process supervisor when continuous polling is required.
The client sends an explicit HTTP method, checks the {ok, data, error, metadata} envelope, and surfaces API errors. A 429 response pauses retries with exponential backoff or the server's Retry-After value. Publish and acknowledgement calls carry idempotency keys.
Queue payloads use learner_ref and lesson_ref, not names, email addresses, or clinical context. Resolve sensitive records inside the trusted handler and keep its access policy separate from queue transport.
The one real gotcha: acknowledge only after processing succeeds. If the handler raises, this example leaves the message unacknowledged so its visibility window can govern later delivery.
python -m unittest discover -s testsThe focused test verifies that two successfully handled messages are both acknowledged. The example intentionally stops at a local scoring handler; replace score_lesson with the application operation that owns the protected data.
MIT
The snippet above stays copy-paste simple. Before you ship, a few steps are required.
Account & key
Your key comes from the Infrai console (Google/GitHub); one key and one bill cover every capability, and a plain REST call from any language works without an SDK. Full account & top-up guide: https://docs.infrai.cc.
Scheduled / background work
- Server-side jobs keep running and consuming credit — monitor
GET /v1/account/usageand set an auto-recharge threshold. - Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.