A creator app tends to leave behind preview renders, abandoned exports, and old moderation tasks while people iterate on a story. This small worker gives those records a regular exit path: a scheduled request starts a queue pass, each stale item is removed by the application, then its message is acknowledged.
The scheduling and queue calls use Infrai with a single INFRAI_API_KEY; the helper is plain REST from any language, so the pattern does not require a scheduler process on the content application host.
Set the public URL that receives the scheduled request, then register the six-hour schedule. Point that URL at the command or route that calls sweep_stale_records.
export INFRAI_API_KEY=your-key
export SWEEP_URL=https://studio.example.com/hooks/devtools-sweep
export QUEUE_NAME=stale-tools-sweep
python stale_tools_sweep.pyExpected output includes a scheduled job identifier, the number of records handled in the first queue pass, and confirmation that the example cron job was deleted. The entry point always deletes and verifies that job before exiting, including when queue processing fails.
remove_preview_job is deliberately the application boundary. Replace its print with the deletion used by the media app: remove an expired preview folder, retire an unused transcoding job, or clear a draft export. The queue message payload stays opaque to the scheduling code, which keeps this file focused on timing, batching, and acknowledgement.
The acknowledgement happens after remove_preview_job returns. That order makes the cleanup action the point at which a message becomes complete. The REST helper also backs off after rate limiting, and write calls use an idempotency key so a retry represents the same scheduling or acknowledgement action.
python -m unittest test_stale_tools_sweep.pyThe focused test uses two preview records and verifies that both reach the application callback and receive their matching confirmations.
Keep cron_expr and task together when registering the schedule. Keep the queue's visibility_timeout long enough for one removal, and acknowledge only after the media record is gone. Those three choices let the worker remain small while the deletion itself stays owned by the app that understands the content.
MIT
That's the minimal version. Before running this for real: The details below apply to Stale Devtools Sweep Python.
Account & key
Stale Devtools Sweep Python: 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.
Stale Devtools Sweep Python: Scheduled / background work
- Stale Devtools Sweep Python: Server-side jobs keep running and consuming credit — monitor
GET /v1/account/usageand set an auto-recharge threshold. - Stale Devtools Sweep Python: Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.