-
Notifications
You must be signed in to change notification settings - Fork 465
Keep meta data around task, even after disabled. #352
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
base: main
Are you sure you want to change the base?
Conversation
@@ -574,8 +574,6 @@ def save(self, *args, **kwargs): | |||
self.routing_key = self.routing_key or None | |||
self.queue = self.queue or None | |||
self.headers = self.headers or None | |||
if not self.enabled: |
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.
does this create any regreassion?
@@ -125,7 +125,6 @@ def is_due(self): | |||
if self.model.one_off and self.model.enabled \ | |||
and self.model.total_run_count > 0: | |||
self.model.enabled = False | |||
self.model.total_run_count = 0 # Reset |
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.
is it backward-incompatible?
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.
please come with an up to date solution
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 ensures that task metadata (last_run_at
and total_run_count
) is preserved when disabling tasks and exposes the run count in the Django admin.
- Stop clearing
total_run_count
for one-off tasks when they disable. - Prevent
last_run_at
from being reset on save if a task is disabled. - Add
total_run_count
as a readonly field in the admin UI.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
django_celery_beat/schedulers.py | Removed the reset of total_run_count when disabling a task |
django_celery_beat/models.py | Deleted logic that cleared last_run_at on save for disabled tasks |
django_celery_beat/admin.py | Added total_run_count to admin form fields and readonly view |
Comments suppressed due to low confidence (2)
django_celery_beat/schedulers.py:128
- [nitpick] Consider adding a comment here explaining why
total_run_count
reset was removed, to clarify the intended behavior for future maintainers.
self.model.no_changes = False # Mark the model entry as changed
django_celery_beat/models.py:577
- Add a unit test to verify that
last_run_at
is preserved when a task is disabled, ensuring this change isn't accidentally reverted.
self._clean_expires()
@@ -133,7 +133,7 @@ class PeriodicTaskAdmin(admin.ModelAdmin): | |||
}), | |||
('Schedule', { | |||
'fields': ('interval', 'crontab', 'solar', 'clocked', | |||
'start_time', 'last_run_at', 'one_off'), | |||
'start_time', 'last_run_at','total_run_count', 'one_off'), |
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.
[nitpick] Insert a space after the comma between 'last_run_at'
and 'total_run_count'
for consistent formatting.
'start_time', 'last_run_at','total_run_count', 'one_off'), | |
'start_time', 'last_run_at', 'total_run_count', 'one_off'), |
Copilot uses AI. Check for mistakes.
total_run_count
to the admin