-
Notifications
You must be signed in to change notification settings - Fork 474
Fix the time calculation problem caused by start_time #844
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
Conversation
Changes:
Why is this change needed?
Impact:
Suggested Solution:
Question
|
|
Changed to draft until the CI passes |
|
I'll take the time to fix this code |
|
I found that After implementing the corresponding method, I will call it within |
|
I created a method for the PeriodicTask model to calculate the accurate start_time, and it calls is_due to calculate the delay when the task is crontab. This way, I don't need to modify the Celery source code, and I fixed this issue in django-celery-beat. I'm not sure if this kind of modification follows the standard practices? |
|
I ran the unit tests for django-celery-beat, and they pass on my Mac but fail on Windows. I would like to use the official CI to run the tests. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #844 +/- ##
==========================================
+ Coverage 87.42% 87.87% +0.45%
==========================================
Files 32 32
Lines 954 965 +11
Branches 76 77 +1
==========================================
+ Hits 834 848 +14
+ Misses 102 100 -2
+ Partials 18 17 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I discovered a bug in my code while trying to write unit tests. I will fix it later and conduct the corresponding tests. |
|
In the process of supplementing the test cases, I found that my code still has some time zone issues, which I will modify tomorrow. |
|
I think I solved the time zone issue. |
|
I will re review it tomorrow |
auvipy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind updating the PR description which fits the latest changes and finding from your work, please? also do you thin this should work on python 3.8?
|
@auvipy |
|
thanks! that's neat! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical scheduling issue in django-celery-beat by ensuring that crontab tasks with a future start_time initialize with the next valid execution time instead of the raw start_time. Key changes include:
- Updating the is_due logic to compute delay using due_start_time based on the crontab schedule.
- Introducing new helper methods in models.py for calculating the due start time.
- Adding tests in t/unit/test_schedulers.py to verify correct behavior for different start_time scenarios and time zones.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| t/unit/test_schedulers.py | New tests covering crontab tasks with future start_time and time zone handling |
| django_celery_beat/schedulers.py | Updated is_due method to compute delay using due_start_time |
| django_celery_beat/models.py | Added helper methods for calculating due start time |
Files not reviewed (1)
- requirements/test.txt: Language not supported
Comments suppressed due to low confidence (2)
django_celery_beat/schedulers.py:119
- [nitpick] Consider renaming 'now_tz' to 'current_tz' for clarity, better reflecting that it represents the current timezone from now.tzinfo.
now_tz = now.tzinfo
django_celery_beat/models.py:393
- [nitpick] Consider renaming the parameter 'start_time' to 'initial_start_time' to more clearly indicate its role in calculating the next valid execution time.
def due_start_time(self, start_time, tz):
Co-authored-by: Copilot <[email protected]>
|
django_celery_beat/schedulers.py:121:80: E501 line too long (81 > 79 characters) |
|
related #867 |
…olve the problem of test.txt dependency
|
Thanks for incorporating new pytest timeout features |
|
hey, we are having regression report related to this pr. can you please check? |
|
@auvipy |
|
Thanks |
Description
This PR fixes a critical scheduling issue in
django-celery-beatwhen a crontab-type task is configured with astart_timeset to a future time.Problem Analysis
self._heap), tasks are sorted by theirevent_t.timefield.start_time > now, the initialevent_t.timewas incorrectly set tostart_timeinstead of the next valid execution time based on the crontab schedule.start_timewas the smallest future timestamp), blocking other tasks from being executed until thestart_timewas reached.Solution
event_t.timegeneration logic during heap initialization for crontab tasks with futurestart_timevalues.start_time, theevent_t.timeis now calculated as the next valid execution time derived from the crontab schedule relative tostart_time.0 * * * *) withstart_time=2024-01-01 12:00:00(future time), the initialevent_t.timewill be2024-01-01 12:00:00(first valid run) instead of the current time.start_time, preventing heap blockage.Changes
is_duemethod inschedulers.pyto:start_timeExpected Behavior
start_timewill no longer block the scheduler heap.fixes #843