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)
break
except asyncpg.exceptions.DeadlockDetectedError:
except (
asyncpg.exceptions.PostgresError,
asyncpg.exceptions.InterfaceError,
):
continue
for _ in range(3):
@@ -153,7 +156,10 @@ class Calls(base.Cog):
)
break
except asyncpg.exceptions.DeadlockDetectedError:
except (
asyncpg.exceptions.PostgresError,
asyncpg.exceptions.InterfaceError,
):
continue
@commands.command(aliases=["c"])
@@ -950,13 +956,12 @@ class Calls(base.Cog):
pass
message_replies = await redis.hget(
constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id,
message.id
constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id, message.id
)
if message_replies is None:
return
for message_id in message_replies.decode().split(","):
try:
await webhook.edit_message(message_id, embed=None)
+3
View File
@@ -9,6 +9,7 @@ import discord
from discord import errors
from discord.ext import commands
import tortoise
from tortoise import transactions, expressions
from payphone import bot
@@ -301,6 +302,8 @@ class Mods(base.Cog):
await self.bot.get_cog("Calls").flush_messages()
await tortoise.Tortoise.close_connections()
await ctx.send("⚡ Messages were flushed, payphone will shut down.")
sys.exit()
+2
View File
@@ -9,6 +9,8 @@ from payphone.core import config
async def init() -> None:
"""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.generate_schemas(safe=True)