Try a new create task and lower max_messages by half

This commit is contained in:
Jeremy Zhang 2019-03-05 19:38:40 +00:00
parent 725823a64c
commit ce205daa0e
2 changed files with 14 additions and 7 deletions

View File

@ -21,9 +21,14 @@ logging.getLogger('sqlalchemy')
# except raven.exceptions.InvalidDsn: # except raven.exceptions.InvalidDsn:
# pass # pass
try:
create_task = asyncio.ensure_future
except AttributeError:
create_task = getattr(asyncio, 'async')
class Titan(discord.AutoShardedClient): class Titan(discord.AutoShardedClient):
def __init__(self): def __init__(self):
super().__init__(max_messages=20000) super().__init__(max_messages=10000)
self.aiosession = aiohttp.ClientSession(loop=self.loop) self.aiosession = aiohttp.ClientSession(loop=self.loop)
self.http.user_agent += ' TitanEmbeds-Bot' self.http.user_agent += ' TitanEmbeds-Bot'
self.redisqueue = RedisQueue(self, config["redis-uri"]) self.redisqueue = RedisQueue(self, config["redis-uri"])
@ -63,7 +68,7 @@ class Titan(discord.AutoShardedClient):
async def start(self): async def start(self):
await self.redisqueue.connect() await self.redisqueue.connect()
self.loop.create_task(self.redisqueue.subscribe()) create_task(self.redisqueue.subscribe())
await super().start(config["bot-token"]) await super().start(config["bot-token"])
async def on_ready(self): async def on_ready(self):

View File

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