Skip to content
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

Merged
merged 2 commits into from
Dec 5, 2024
Merged

feat: Admin improvements #14

merged 2 commits into from
Dec 5, 2024

Conversation

khvn26
Copy link
Member

@khvn26 khvn26 commented Nov 22, 2024

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.

- Add `last_run_finished_at` admin field
- Add `unlock` admin action
@khvn26 khvn26 requested a review from matthewelwell November 22, 2024 18:15
Comment on lines +25 to +28
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
Copy link
Contributor

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? 🤔

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@khvn26 khvn26 requested a review from matthewelwell December 4, 2024 11:27
Comment on lines +25 to +28
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
Copy link
Contributor

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.

@khvn26 khvn26 merged commit f92adfd into main Dec 5, 2024
2 checks passed
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