Ratelimited gateway queue for multiserviced bots. See https://github.com/twilight-rs/gateway-queue
100K+
If your bot's shards are multi-processed, then a good choice is to use the Gateway Queue. The Gateway Queue is a lightweight but powerful application that you can host to queue shards across all of your processes.
The Gateway Queue is library and language agnostic: it's an HTTP server that you call whenever a shard needs to reconnect to the gateway.
When one of your shards disconnects and needs to perform a full reconnect, then it needs to start a new session with the gateway. If you have multiple processes managing shards, then you may not have communication between these processes. The problems start to happen when multiple shards from these processes try to reconnect at the same time: all but 1 (with the exception of max_concurrency > 1 enabled bots, more on that below) will get ratelimited.
This is because there's a 5 second ratelimit between new sessions. By sending an HTTP request to the Gateway Queue, it will ratelimit the requests and "stall" them, responding with a friendly message once that shard can reconnect:
{"message": "You're free to connect now! :)"}
The API is pretty minimal, probably. It's just an HTTP request:
reqwest::get("http://gateway-queue").await?;
No headers, body, or particular method need to be set. They're all ignored. The request will get a response once the request has gone through the queue.
$ docker run -itd -e HOST=0.0.0.0 -e PORT=5000 twilightrs/gateway-queue
HOST and PORT are the two main environment variables. Optionally, you can add DISCORD_TOKEN and set it to your bot's token to enable automatic support for max_concurrency API features.
Content type
Image
Digest
sha256:24e85f243…
Size
1.7 MB
Last updated
over 3 years ago
docker pull twilightrs/gateway-queue