Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

feat: Admin improvements#14

Merged
khvn26 merged 2 commits intomainfrom
feat/admin-improvements
Dec 5, 2024
Merged

feat: Admin improvements#14
khvn26 merged 2 commits intomainfrom
feat/admin-improvements

Conversation

@khvn26
Copy link
Copy Markdown
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 thread task_processor/admin.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread task_processor/admin.py
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
Copy Markdown
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants