aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar kwzrd <[email protected]>2020-08-29 18:29:24 +0200
committerGravatar kwzrd <[email protected]>2020-08-29 18:29:39 +0200
commitc58ae662069d098dae45a36a5203b6d5f0048924 (patch)
tree5399e23ddffc8e15d213fba0a2b1f6d2ce0689ae
parentVerification: improve allowed mentions handling (diff)
Verification: add helper for stopping tasks
-rw-r--r--bot/cogs/verification.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py
index 0ae3c5b4c..a013a1b12 100644
--- a/bot/cogs/verification.py
+++ b/bot/cogs/verification.py
@@ -157,8 +157,7 @@ class Verification(Cog):
This is necessary, as tasks are not automatically cancelled on cog unload.
"""
- self.update_unverified_members.cancel()
- self.ping_unverified.cancel()
+ self._stop_tasks(gracefully=False)
@property
def mod_log(self) -> ModLog:
@@ -179,6 +178,21 @@ class Verification(Cog):
self.update_unverified_members.start()
self.ping_unverified.start()
+ def _stop_tasks(self, *, gracefully: bool) -> None:
+ """
+ Stop the update users & ping @Unverified tasks.
+
+ If `gracefully` is True, the tasks will be able to finish their current iteration.
+ Otherwise, they are cancelled immediately.
+ """
+ log.info(f"Stopping internal tasks ({gracefully=})")
+ if gracefully:
+ self.update_unverified_members.stop()
+ self.ping_unverified.stop()
+ else:
+ self.update_unverified_members.cancel()
+ self.ping_unverified.cancel()
+
# region: automatically update unverified users
async def _verify_kick(self, n_members: int) -> bool:
@@ -607,9 +621,7 @@ class Verification(Cog):
"""Stop verification tasks."""
log.info("Stopping verification tasks")
- self.update_unverified_members.cancel()
- self.ping_unverified.cancel()
-
+ self._stop_tasks(gracefully=False)
await self.task_cache.set("tasks_running", 0)
colour = discord.Colour.blurple()