From 57d0a746215e7e9fa44092b131d3b32f9a141b66 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sun, 6 Jan 2019 00:08:12 +0000 Subject: [PATCH] Relinquish resources to the bot every 10 publishes in redisqueue --- discordbot/titanembeds/redisqueue.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/discordbot/titanembeds/redisqueue.py b/discordbot/titanembeds/redisqueue.py index 79474e7..6450a7a 100644 --- a/discordbot/titanembeds/redisqueue.py +++ b/discordbot/titanembeds/redisqueue.py @@ -36,11 +36,17 @@ class RedisQueue: await self.bot.wait_until_ready() subscriber = await self.sub_connection.start_subscribe() await subscriber.subscribe(["discord-api-req"]) + count = 0 while True: reply = await subscriber.next_published() request = json.loads(reply.value) resource = request["resource"] self.dispatch(resource, request["key"], request["params"]) + count = count + 1 + if count > 10: + count = 0 + elif count == 10: + await asyncio.sleep(0) def dispatch(self, event, key, params): method = "on_" + event