diff options
| -rw-r--r-- | bot/exts/christmas/advent_of_code/_cog.py | 6 | ||||
| -rw-r--r-- | bot/exts/christmas/advent_of_code/_helpers.py | 11 | 
2 files changed, 17 insertions, 0 deletions
| diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py index 0968dd26..0671203e 100644 --- a/bot/exts/christmas/advent_of_code/_cog.py +++ b/bot/exts/christmas/advent_of_code/_cog.py @@ -30,6 +30,7 @@ AOC_WHITELIST = AOC_WHITELIST_RESTRICTED + (Channels.advent_of_code,)  async def countdown_status(bot: commands.Bot) -> None:      """Set the playing status of the bot to the minutes & hours left until the next day's challenge.""" +    log.info("Started `AoC Status Countdown` task")      while _helpers.is_in_advent():          _, time_left = _helpers.time_left_to_aoc_midnight() @@ -62,6 +63,7 @@ async def day_countdown(bot: commands.Bot) -> None:      Once we have calculated this we should then sleep that number and when the time is reached, ping      the Advent of Code role notifying them that the new challenge is ready.      """ +    log.info("Started `Daily AoC Notification` task")      while _helpers.is_in_advent():          tomorrow, time_left = _helpers.time_left_to_aoc_midnight() @@ -127,9 +129,13 @@ class AdventOfCode(commands.Cog):          countdown_coro = day_countdown(self.bot)          self.countdown_task = self.bot.loop.create_task(countdown_coro) +        self.countdown_task.set_name("Daily AoC Notification") +        self.countdown_task.add_done_callback(_helpers.background_task_callback)          status_coro = countdown_status(self.bot)          self.status_task = self.bot.loop.create_task(status_coro) +        self.status_task.set_name("AoC Status Countdown") +        self.status_task.add_done_callback(_helpers.background_task_callback)      @commands.group(name="adventofcode", aliases=("aoc",))      @override_in_channel(AOC_WHITELIST) diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py index d883c09f..da139e40 100644 --- a/bot/exts/christmas/advent_of_code/_helpers.py +++ b/bot/exts/christmas/advent_of_code/_helpers.py @@ -1,3 +1,4 @@ +import asyncio  import collections  import datetime  import json @@ -407,3 +408,13 @@ def time_left_to_aoc_midnight() -> Tuple[datetime.datetime, datetime.timedelta]:      # Calculate the timedelta between the current time and midnight      return tomorrow, tomorrow - datetime.datetime.now(EST) + + +def background_task_callback(task: asyncio.Task) -> None: +    """Check if the finished background task failed to make sure we log errors.""" +    if task.cancelled(): +        log.info(f"Background task `{task.get_name()}` was cancelled.") +    elif exception := task.exception(): +        log.error(f"Background task `{task.get_name()}` failed:", exc_info=exception) +    else: +        log.info(f"Background task `{task.get_name()}` exited normally.") | 
