logging hourly

This commit is contained in:
Gaël Honorez
2024-01-02 08:58:01 +01:00
parent f8b9ba7eb6
commit a3719f1a35

View File

@@ -79,9 +79,20 @@ class SubStackTask:
# Calculate the time until 6 AM next day
next_run = (now + datetime.timedelta(days=1)).replace(hour=6, minute=5, second=0, microsecond=0)
sleep_seconds = (next_run - now).total_seconds()
LOG.info("Waiting for " + str(sleep_seconds) + " seconds for next scan")
# Wait until the next run time
await asyncio.sleep(sleep_seconds)
while sleep_seconds > 0:
# Check if the remaining time is a multiple of 3600 seconds
if sleep_seconds % 3600 == 0:
LOG.info(f"Waiting for {sleep_seconds} seconds for next scan")
# Wait for some time before checking again
# Here, we choose to wait for less than an hour (e.g., 59 minutes) to ensure we hit the hourly mark
await asyncio.sleep(min(sleep_seconds, 59 * 60))
# Recalculate the remaining sleep time
now = datetime.datetime.now()
sleep_seconds = (next_run - now).total_seconds()
LOG.info("Going to run the daily task")
# Run the daily task
await self.daily_task()