Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weekly job fails with interval > 1 #613

Open
maxnyman opened this issue Feb 5, 2024 · 0 comments
Open

Weekly job fails with interval > 1 #613

maxnyman opened this issue Feb 5, 2024 · 0 comments

Comments

@maxnyman
Copy link

maxnyman commented Feb 5, 2024

Some assumptions are made in the code, which breaks if the interval is > 1.

Attached some unit test to expose the error:
scheduler_weeks_test.txt

To fix:

In _schedule_next_run replace the lines from starting with if days_ahead <= 0: with the following

            if days_ahead < 0:  # Target day already happened this week
                days_ahead += 7
            if self.last_run is None:
                self.next_run += datetime.timedelta(days_ahead) - self.period
            elif self.last_run + self.period < datetime.datetime.now():
                self.next_run += datetime.timedelta(days_ahead) - datetime.timedelta(days=7)

And a bit further down, at the end of the function, remove the following completely

        if self.start_day is not None and self.at_time is not None:
            # Let's see if we will still make that time we specified today
            if (self.next_run - datetime.datetime.now()).days >= 7:
                self.next_run -= self.period
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant