Skip to content

Add seconds and milliseconds support in cron_offset #467

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

Closed
wants to merge 1 commit into from

Conversation

borisalekseev
Copy link

Cron is insensitive to seconds. But cron_offset accepts datetime.timedelta, which has seconds in it. This PR adds sensitivity to seconds and milliseconds from cron_offset.

if task.cron_offset and isinstance(task.cron_offset, timedelta):
now += task.cron_offset
additional_seconds += task.cron_offset.seconds + (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you use seconds, which might produce unexpected results.

Suggested change
additional_seconds += task.cron_offset.seconds + (
additional_seconds += task.cron_offset.total_seconds() + (

In this example if you specify minutes and hours it will also correctly work. Or was it implemented like so on purpose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an even worse mistake here, as you can see. The idea was that additional_seconds is the remainder of the seconds from the entire cron_offset. Now fixed it.

@borisalekseev
Copy link
Author

this will not work correctly with an update-interval greater than a second

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

Successfully merging this pull request may close these issues.

2 participants