Skip to content

Duplicate runs for every 15 minutes schedule #3

@CameronNemo

Description

@CameronNemo

Schedule of "*/15 * * * *"

These are the results:

2023-07-12 21:55:12,303 WARNING scheduled_task run next_run_time: 2023-07-12 22:00:00.303164 - default_args: {'args': [], 'kwargs': {}}
INFO:     Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
2023-07-12 22:00:00,304 WARNING scheduled_task run next_run_time: 2023-07-12 22:01:00.304216 - default_args: {'args': [], 'kwargs': {}}
2023-07-12 22:01:00,306 WARNING scheduled_task run next_run_time: 2023-07-12 22:15:00.305922 - default_args: {'args': [], 'kwargs': {}}
2023-07-12 22:15:00,308 WARNING scheduled_task run next_run_time: 2023-07-12 22:16:00.307897 - default_args: {'args': [], 'kwargs': {}}
2023-07-12 22:16:00,309 WARNING scheduled_task run next_run_time: 2023-07-12 22:30:00.309563 - default_args: {'args': [], 'kwargs': {}}

Edit: tested also with every five minute runs. Similar results. I believe I have narrowed down where the issue occurs to this logic:

current = datetime.datetime.now()
while True:
if current.month not in months:
current = current + datetime.timedelta(hours=23-current.hour, minutes=60-current.minute)
continue
if not current.weekday() in weekdays:
current = current + datetime.timedelta(hours=23-current.hour, minutes=60-current.minute)
continue
if not current.day in days:
current = current + datetime.timedelta(hours=23-current.hour, minutes=60-current.minute)
continue
if current.hour not in hours:
current = current + datetime.timedelta(minutes=59-current.minute, seconds=60-current.second)
continue
if current.minute not in minutes:
current = current + datetime.timedelta(seconds=60-current.second)
continue
else:
current = current #+ datetime.timedelta(seconds=60-current.second)
break
delta = current - datetime.datetime.now()
delta_seconds = delta.total_seconds()
if delta_seconds < 60:
delta_seconds = 60 - current.second
current = current + datetime.timedelta(seconds=delta_seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions