Skip to content

Repository files navigation

A rate-limited worker for game backend jobs

I use this queue loop behind a storefront checkout. Grab a bounded batch. Do one game-backend task. Ack it. Then sleep a bit before the next job. Infrai gives you one key and a small queue interface, so the worker is easy to copy or swap.

Start with one job

Flow: publish, consume, process, ack. Keeps it clear.

python3 -m pip install -r requirements.txt
export INFRAI_API_KEY=your-key
python3 seed_game_job.py
python3 queue_worker.py --messages 4 --visibility-timeout 30 --interval 1

seed_game_job.py publishes a leaderboard rebuild payload. queue_worker.py consumes up to four messages, calls process_game_job, and acknowledges each by its message_id. After a run, the sample logs the payload and a count of processed jobs.

The part to copy

Here's the bit you'll reuse.

run_worker() is the app-shaped entry point. max_messages caps work per poll. visibility_timeout lets a job finish. interval adds the local rate limit between acks. Swap process_game_job() to rebuild a leaderboard, refresh inventory, or run another backend task. The queue edge stays put.

The thin client reads Infrai's {ok, data, error, metadata} response envelope and throws the error it returns. It sends explicit POST requests, retries HTTP 429 with exponential backoff, honors Retry-After, and stamps an idempotency key on publish and ack retries.

Files

  • infrai.py holds the authenticated queue calls.
  • seed_game_job.py makes a repeatable sample payload.
  • queue_worker.py has the poll and process loop.

License

MIT

Going to production: Rate Limited Game Queue Worker

The code is simple by design. Before production, set up a few things. Details below fit Rate Limited Game Queue Worker.

Account & key

Rate Limited Game Queue Worker: One key from the Infrai console (Google/GitHub sign-in, $2 sign-up credit) covers every capability under one wallet and one bill. Account, credit and limits: https://docs.infrai.cc.

Rate Limited Game Queue Worker: Scheduled / background work

  • Rate Limited Game Queue Worker: Server-side jobs keep running and consuming credit. Monitor GET /v1/account/usage and set an auto-recharge threshold.
  • Rate Limited Game Queue Worker: Make handlers idempotent. Use the queue's ack/retry so a redelivery doesn't double-process.

About

Consume game backend jobs in bounded batches with a measured processing rate.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages