Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vbabiy
Copy link
Contributor

@vbabiy vbabiy commented Jun 13, 2020

  • added total_run_count to the admin
  • don't clear out last_run_at, on disabling a task.
  • don't clear out total_run_count on one of tasks.

@@ -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:
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

is it backward-incompatible?

@auvipy auvipy closed this Oct 13, 2022
@auvipy auvipy reopened this Oct 13, 2022
Copy link
Member

@auvipy auvipy left a 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

@auvipy auvipy requested a review from Copilot June 19, 2025 06:48
Copy link

@Copilot Copilot AI left a 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'),
Copy link
Preview

Copilot AI Jun 19, 2025

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.

Suggested change
'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.

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