mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
fix: Daily task scheduler can be off by an hour (#3820)
This commit is contained in:
parent
e80ba7dff3
commit
b0cc7c4c25
@ -42,14 +42,21 @@ async def schedule_daily():
|
|||||||
hour_target = 23
|
hour_target = 23
|
||||||
minute_target = 45
|
minute_target = 45
|
||||||
|
|
||||||
hours_until = ((hour_target - now.hour) % 24) or 24
|
next_schedule = now.replace(hour=hour_target, minute=minute_target, second=0, microsecond=0)
|
||||||
minutes_until = (minute_target - now.minute) % 60
|
delta = next_schedule - now
|
||||||
logger.debug("Hours until %s and minutes until %s", str(hours_until), str(minutes_until))
|
if delta < timedelta(0):
|
||||||
|
next_schedule = next_schedule + timedelta(days=1)
|
||||||
|
delta = next_schedule - now
|
||||||
|
|
||||||
delta = timedelta(hours=hours_until, minutes=minutes_until)
|
hours_until, seconds_reminder = divmod(delta.total_seconds(), 3600)
|
||||||
target_time = (now + delta).replace(microsecond=0, second=0)
|
minutes_until, seconds_reminder = divmod(seconds_reminder, 60)
|
||||||
|
seconds_until = round(seconds_reminder)
|
||||||
|
logger.debug("Time left: %02d:%02d:%02d", hours_until, minutes_until, seconds_until)
|
||||||
|
|
||||||
|
target_time = next_schedule.replace(microsecond=0, second=0)
|
||||||
logger.info("Daily tasks scheduled for %s", str(target_time))
|
logger.info("Daily tasks scheduled for %s", str(target_time))
|
||||||
wait_seconds = (target_time - now).total_seconds()
|
|
||||||
|
wait_seconds = delta.total_seconds()
|
||||||
await asyncio.sleep(wait_seconds)
|
await asyncio.sleep(wait_seconds)
|
||||||
await run_daily()
|
await run_daily()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user