Skip to content

Commit

Permalink
feat: Admin improvements
Browse files Browse the repository at this point in the history
- Add `last_run_finished_at` admin field
- Add `unlock` admin action
  • Loading branch information
khvn26 committed Nov 22, 2024
1 parent c43af41 commit 21b2cec
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions task_processor/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import datetime
from django.contrib import admin
from django.http import HttpRequest
from django.db.models import QuerySet

from task_processor.models import RecurringTask

Expand All @@ -18,3 +21,16 @@ def last_run_status(self, instance: RecurringTask) -> str | None:
if last_run := instance.task_runs.order_by("-started_at").first():
return last_run.result
return None

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

@admin.action(description="Unlock selected tasks")
def unlock(
self,
request: HttpRequest,
queryset: QuerySet[RecurringTask],
) -> None:
queryset.update(is_locked=False)

0 comments on commit 21b2cec

Please sign in to comment.