Merge pull request #28 from Payphone-Bot/27-asyncpg-exceptions-crash-flush_messages-task

fix(bot): 🐛 Messages not being flushed to the DB after `asyncpg.e…
This commit is contained in:
Rafael Bradley
2024-10-21 14:04:12 -03:00
committed by GitHub
3 changed files with 15 additions and 5 deletions
+10 -5
View File
@@ -143,7 +143,10 @@ class Calls(base.Cog):
await models.Message.bulk_create(message_rows, batch_size=500) await models.Message.bulk_create(message_rows, batch_size=500)
break break
except asyncpg.exceptions.DeadlockDetectedError: except (
asyncpg.exceptions.PostgresError,
asyncpg.exceptions.InterfaceError,
):
continue continue
for _ in range(3): for _ in range(3):
@@ -153,7 +156,10 @@ class Calls(base.Cog):
) )
break break
except asyncpg.exceptions.DeadlockDetectedError: except (
asyncpg.exceptions.PostgresError,
asyncpg.exceptions.InterfaceError,
):
continue continue
@commands.command(aliases=["c"]) @commands.command(aliases=["c"])
@@ -950,13 +956,12 @@ class Calls(base.Cog):
pass pass
message_replies = await redis.hget( message_replies = await redis.hget(
constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id, constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id, message.id
message.id
) )
if message_replies is None: if message_replies is None:
return return
for message_id in message_replies.decode().split(","): for message_id in message_replies.decode().split(","):
try: try:
await webhook.edit_message(message_id, embed=None) await webhook.edit_message(message_id, embed=None)
+3
View File
@@ -9,6 +9,7 @@ import discord
from discord import errors from discord import errors
from discord.ext import commands from discord.ext import commands
import tortoise
from tortoise import transactions, expressions from tortoise import transactions, expressions
from payphone import bot from payphone import bot
@@ -301,6 +302,8 @@ class Mods(base.Cog):
await self.bot.get_cog("Calls").flush_messages() await self.bot.get_cog("Calls").flush_messages()
await tortoise.Tortoise.close_connections()
await ctx.send("⚡ Messages were flushed, payphone will shut down.") await ctx.send("⚡ Messages were flushed, payphone will shut down.")
sys.exit() sys.exit()
+2
View File
@@ -9,6 +9,8 @@ from payphone.core import config
async def init() -> None: async def init() -> None:
"""Initialize the database and it's connections.""" """Initialize the database and it's connections."""
await tortoise.Tortoise.close_connections()
await tortoise.Tortoise.init(config.TORTOISE_ORM, use_tz=True) await tortoise.Tortoise.init(config.TORTOISE_ORM, use_tz=True)
await tortoise.Tortoise.generate_schemas(safe=True) await tortoise.Tortoise.generate_schemas(safe=True)