diff options
| author | 2019-04-15 09:04:23 +0200 | |
|---|---|---|
| committer | 2019-04-15 09:04:23 +0200 | |
| commit | cf9485985336aaf0e90617a124c52d6f768c5ba3 (patch) | |
| tree | 509eb45a8740183111ae46690a3114fd6c9c97f3 | |
| parent | Cleaning up the fix by removing unnecessary initial None and None check (diff) | |
Fixing the off-by-one-second bug by adding additional second to sleep time
| -rw-r--r-- | bot/cogs/off_topic_names.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 99dc725d2..58a53118e 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -47,14 +47,12 @@ async def update_names(bot: Bot, headers: dict): website via the bot's `http_session`. """ - # To ensure we only cycle once per day, we increase the reference midnight point - # by one day each time the task runs instead of relying on "the most recent" - # midnight, since that may fail if the task is triggered early. - midnight = midnight = datetime.utcnow().replace(microsecond=0, second=0, minute=0, hour=0) while True: - midnight += timedelta(days=1) - seconds_to_sleep = (midnight - datetime.utcnow()).seconds - log.debug(f"update_names: seconds to sleep {seconds_to_sleep}") + # 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) response = await bot.http_session.get( |