Sleep a bit more if bot isnt responding

This commit is contained in:
Jeremy Zhang
2019-03-05 21:02:33 +00:00
parent 29c1d8bfda
commit c62661ec6c
3 changed files with 254 additions and 13 deletions

View File

@ -8,11 +8,6 @@ import traceback
import sys
import re
try:
create_task = asyncio.ensure_future
except AttributeError:
create_task = getattr(asyncio, 'async')
class RedisQueue:
def __init__(self, bot, redis_uri):
self.bot = bot
@ -42,7 +37,10 @@ class RedisQueue:
subscriber = await self.sub_connection.start_subscribe()
await subscriber.subscribe(["discord-api-req"])
count = 0
while not self.bot.is_closed():
while True:
if not self.bot.is_ready() or self.bot.is_closed():
await asyncio.sleep(1)
continue
reply = await subscriber.next_published()
request = json.loads(reply.value)
resource = request["resource"]
@ -56,7 +54,7 @@ class RedisQueue:
def dispatch(self, event, key, params):
method = "on_" + event
if hasattr(self, method):
create_task(self._run_event(method, key, params))
self.bot.loop.create_task(self._run_event(method, key, params))
async def _run_event(self, event, key, params):
try: