From e15d53339fbbadf0efc71478f2eab974bca0f378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl?= Date: Mon, 24 Nov 2025 08:50:58 +0100 Subject: [PATCH] fixing the loop --- presquegratos.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/presquegratos.py b/presquegratos.py index ddcf015..29b7316 100644 --- a/presquegratos.py +++ b/presquegratos.py @@ -996,17 +996,29 @@ def _format_duration(seconds: float) -> str: async def run_forever_sunday_noon(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") + while True: now = datetime.now() - days = (6 - now.weekday()) % 7 - target = (now + timedelta(days=days)).replace(hour=12, minute=0, second=0, microsecond=0) + days_ahead = 6 - now.weekday() + if days_ahead < 0: + days_ahead += 7 + + target = (now + timedelta(days=days_ahead)).replace( + hour=12, minute=0, second=0, microsecond=0 + ) + + # If it's already past this Sunday's noon, schedule for next week + if target <= now: + target += timedelta(days=7) + sleep_seconds = (target - now).total_seconds() + while sleep_seconds > 0: LOG.info("Waiting for %s for next scan", _format_duration(sleep_seconds)) await asyncio.sleep(min(sleep_seconds, 5 * 60)) now = datetime.now() sleep_seconds = (target - now).total_seconds() - + LOG.info("Going to run the weekly task") await run_weekly()