logging hourly
This commit is contained in:
@@ -79,12 +79,23 @@ class SubStackTask:
|
|||||||
# Calculate the time until 6 AM next day
|
# Calculate the time until 6 AM next day
|
||||||
next_run = (now + datetime.timedelta(days=1)).replace(hour=6, minute=5, second=0, microsecond=0)
|
next_run = (now + datetime.timedelta(days=1)).replace(hour=6, minute=5, second=0, microsecond=0)
|
||||||
sleep_seconds = (next_run - now).total_seconds()
|
sleep_seconds = (next_run - now).total_seconds()
|
||||||
LOG.info("Waiting for " + str(sleep_seconds) + " seconds for next scan")
|
|
||||||
# Wait until the next run time
|
while sleep_seconds > 0:
|
||||||
await asyncio.sleep(sleep_seconds)
|
# 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")
|
LOG.info("Going to run the daily task")
|
||||||
# Run the daily task
|
# Run the daily task
|
||||||
await self.daily_task()
|
await self.daily_task()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user