From 99eea5edadb7bea4601d4ac37b69b89ae9afbf66 Mon Sep 17 00:00:00 2001 From: Dave Gaeddert Date: Thu, 18 Jan 2024 16:42:01 -0600 Subject: [PATCH] Show waiting and running job stats --- bolt-jobs/bolt/jobs/admin.py | 18 ++++++++++++++++++ bolt-jobs/bolt/jobs/models.py | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/bolt-jobs/bolt/jobs/admin.py b/bolt-jobs/bolt/jobs/admin.py index a85c035310..e01738284d 100644 --- a/bolt-jobs/bolt/jobs/admin.py +++ b/bolt-jobs/bolt/jobs/admin.py @@ -99,6 +99,20 @@ def get_link(self): return JobResultViewset.ListView.get_absolute_url() + "?filter=Retried" +class WaitingJobsCard(Card): + title = "Waiting Jobs" + + def get_number(self): + return Job.objects.waiting().count() + + +class RunningJobsCard(Card): + title = "Running Jobs" + + def get_number(self): + return Job.objects.running().count() + + @register_viewset class JobRequestViewset(AdminModelViewset): class ListView(AdminModelListView): @@ -117,6 +131,10 @@ class ListView(AdminModelListView): model = Job fields = ["id", "job_class", "priority", "created_at", "started_at"] actions = ["Delete"] + cards = [ + WaitingJobsCard, + RunningJobsCard, + ] def perform_action(self, action: str, target_pks: list): if action == "Delete": diff --git a/bolt-jobs/bolt/jobs/models.py b/bolt-jobs/bolt/jobs/models.py index 6cb8d32b52..bb726d961f 100644 --- a/bolt-jobs/bolt/jobs/models.py +++ b/bolt-jobs/bolt/jobs/models.py @@ -86,6 +86,12 @@ def convert_to_job(self, *, worker_uuid=None): class JobQuerySet(models.QuerySet): + def running(self): + return self.filter(started_at__isnull=False) + + def waiting(self): + return self.filter(started_at__isnull=True) + def mark_lost_jobs(self): # Lost jobs are jobs that have been pending for too long, # and probably never going to get picked up by a worker process.