From 152f11d2d17bcb999af518bd78eec125353bd305 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Tue, 24 Sep 2019 13:15:57 +0200 Subject: Override waiting time to half an hour If an exception occurred --- bot/cogs/off_topic_names.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 487ce6852..bdece9161 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -42,13 +42,15 @@ class OffTopicName(Converter): async def update_names(bot: Bot) -> None: """Background updater task that performs the daily channel name update.""" + skip_sleep = False while True: # Since we truncate the compute timedelta to seconds, we add one second to ensure # we go past midnight in the `seconds_to_sleep` set below. today_at_midnight = datetime.utcnow().replace(microsecond=0, second=0, minute=0, hour=0) next_midnight = today_at_midnight + timedelta(days=1) seconds_to_sleep = (next_midnight - datetime.utcnow()).seconds + 1 - await asyncio.sleep(seconds_to_sleep) + if skip_sleep is False: + await asyncio.sleep(seconds_to_sleep) try: channel_0_name, channel_1_name, channel_2_name = await bot.api_client.get( @@ -56,6 +58,8 @@ async def update_names(bot: Bot) -> None: ) except ResponseCodeError as e: log.error(f"Failed to get new off topic channel names: code {e.response.status}") + skip_sleep = True + await asyncio.sleep(1800) continue channel_0, channel_1, channel_2 = (bot.get_channel(channel_id) for channel_id in CHANNELS) @@ -66,6 +70,7 @@ async def update_names(bot: Bot) -> None: "Updated off-topic channel names to" f" {channel_0_name}, {channel_1_name} and {channel_2_name}" ) + skip_sleep = False class OffTopicNames(Cog): -- cgit v1.2.3