From 0fc93a01928d421d45033072ef02867b6446ec90 Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 20 Jul 2022 21:40:42 +0200 Subject: [PATCH] Fix author queue stuck --- main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b2671a3..71d789d 100644 --- a/main.py +++ b/main.py @@ -200,6 +200,10 @@ async def main(): global TASK_AUTHORS, TASK_QUEUE bot.loop.create_task(bot.connect()) + def _lower_author_task_count(task_author): + TASK_AUTHORS.setdefault(task_author, 1) + TASK_AUTHORS[task_author] -= 1 + # main loop while True: random.shuffle(TASK_QUEUE._queue) @@ -209,12 +213,14 @@ async def main(): images = await task.get_images() except Exception as ex: bot.send("PRIVMSG", target=task.channel, message=f"could not fetch images: {ex}") + _lower_author_task_count(task.author) continue try: image = await task.process_images(images) except Exception as ex: bot.send("PRIVMSG", target=task.channel, message=f"could not process images: {ex}") + _lower_author_task_count(task.author) continue image_bytes = BytesIO() @@ -226,10 +232,10 @@ async def main(): url = await task.post_image(image_bytes) except Exception as ex: bot.send("PRIVMSG", target=task.channel, message=str(ex)) + _lower_author_task_count(task.author) continue - TASK_AUTHORS.setdefault(task.author, 1) - TASK_AUTHORS[task.author] -= 1 + _lower_author_task_count(task.author) bot.send("PRIVMSG", target=task.channel, message=f"{url} ({task.author})") await asyncio.sleep(10)