aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dennis Pham <[email protected]>2020-08-05 20:29:49 -0400
committerGravatar GitHub <[email protected]>2020-08-05 20:29:49 -0400
commit02cc7a808fef79d4dbca599ec8477ccb13d640b0 (patch)
tree3fe0ed12a77a781ba9367d6a9d36cea2be12d0eb
parentMerge pull request #1091 from python-discord/kwzrd/fix-1090 (diff)
parentMerge branch 'master' into bug/backend/1080/cog-reload-cancel-scheduler (diff)
Merge pull request #1087 from python-discord/bug/backend/1080/cog-reload-cancel-scheduler
Cancel scheduled tasks when cogs unload
-rw-r--r--bot/cogs/filtering.py4
-rw-r--r--bot/cogs/moderation/scheduler.py4
-rw-r--r--bot/cogs/moderation/silence.py3
-rw-r--r--bot/cogs/reminders.py4
4 files changed, 14 insertions, 1 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 64afd184d..4ec95ad73 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -99,6 +99,10 @@ class Filtering(Cog):
self.bot.loop.create_task(self.reschedule_offensive_msg_deletion())
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
def _get_filterlist_items(self, list_type: str, *, allowed: bool) -> list:
"""Fetch items from the filter_list_cache."""
return self.bot.filter_list_cache[f"{list_type.upper()}.{allowed}"].keys()
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py
index 601e238c9..75028d851 100644
--- a/bot/cogs/moderation/scheduler.py
+++ b/bot/cogs/moderation/scheduler.py
@@ -31,6 +31,10 @@ class InfractionScheduler:
self.bot.loop.create_task(self.reschedule_infractions(supported_infractions))
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
@property
def mod_log(self) -> ModLog:
"""Get the currently loaded ModLog cog instance."""
diff --git a/bot/cogs/moderation/silence.py b/bot/cogs/moderation/silence.py
index ae4fb7b64..f8a6592bc 100644
--- a/bot/cogs/moderation/silence.py
+++ b/bot/cogs/moderation/silence.py
@@ -152,7 +152,8 @@ class Silence(commands.Cog):
return False
def cog_unload(self) -> None:
- """Send alert with silenced channels on unload."""
+ """Send alert with silenced channels and cancel scheduled tasks on unload."""
+ self.scheduler.cancel_all()
if self.muted_channels:
channels_string = ''.join(channel.mention for channel in self.muted_channels)
message = f"<@&{Roles.moderators}> channels left silenced on cog unload: {channels_string}"
diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py
index b5998cc0e..670493bcf 100644
--- a/bot/cogs/reminders.py
+++ b/bot/cogs/reminders.py
@@ -37,6 +37,10 @@ class Reminders(Cog):
self.bot.loop.create_task(self.reschedule_reminders())
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
async def reschedule_reminders(self) -> None:
"""Get all current reminders from the API and reschedule them."""
await self.bot.wait_until_guild_available()