-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Admin improvements #14
Conversation
- Add `last_run_finished_at` admin field - Add `unlock` admin action
def last_run_finished_at(self, instance: RecurringTask) -> datetime | None: | ||
if last_run := instance.task_runs.order_by("-started_at").first(): | ||
return last_run.finished_at | ||
return None |
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.
What's the intention here? To add this to the list view, or just the detail view? At the moment, I'm not sure it's added to either? 🤔
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.
I'd also be reluctant to add this to the list display as it probably won't perform that well being run for all the records in the view.
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.
Good catch, added the field to list_display
.
I'd also be reluctant to add this to the list display as it probably won't perform that well being run for all the records in the view.
A similiar query is already run for all the records in the view — see last_run_status
. I wouldn't worry too much about performance as the recurring task list is fairly constant.
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.
Yeah, fair enough. I guess there's an argument to say that we could cache the last run between the 2 methods here, but maybe that's over optimisation at this stage.
def last_run_finished_at(self, instance: RecurringTask) -> datetime | None: | ||
if last_run := instance.task_runs.order_by("-started_at").first(): | ||
return last_run.finished_at | ||
return None |
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.
Yeah, fair enough. I guess there's an argument to say that we could cache the last run between the 2 methods here, but maybe that's over optimisation at this stage.
This PR adds a way to bulk unlock recurring tasks from the Django admin.
Additionally, it surfaces the last run time, which helps to determine whether a given recurring task is stuck or not.