From f731c8600c838752c89c3dd0b3330881eddfb7dd Mon Sep 17 00:00:00 2001 From: Frisk Date: Mon, 10 Aug 2020 22:31:53 +0200 Subject: [PATCH] Stop the task when it somehow runs out of wikis --- src/bot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bot.py b/src/bot.py index 4089ffd..2a6c147 100644 --- a/src/bot.py +++ b/src/bot.py @@ -72,12 +72,18 @@ class RcQueue: if not self[group]["query"]: # if there is no wiki left in the queue, get rid of the task logger.debug(f"{group} no longer has any wikis queued!") all_wikis[wiki].rc_active = -1 - self[group]["task"].cancel() - del self.domain_list[group] + await self.stop_task_group(group) + + async def stop_task_group(self, group): + self[group]["task"].cancel() + del self.domain_list[group] @asynccontextmanager async def retrieve_next_queued(self, group) -> Generator[QueuedWiki, None, None]: """Retrives next wiki in the queue for given domain""" + if len(self.domain_list[group]["query"]) == 0: + await self.stop_task_group(group) + return try: yield self.domain_list[group]["query"][0] except asyncio.CancelledError: