Skip to content

Commit 99eea5e

Browse files
committed
Show waiting and running job stats
1 parent 1f901b3 commit 99eea5e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

bolt-jobs/bolt/jobs/admin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ def get_link(self):
9999
return JobResultViewset.ListView.get_absolute_url() + "?filter=Retried"
100100

101101

102+
class WaitingJobsCard(Card):
103+
title = "Waiting Jobs"
104+
105+
def get_number(self):
106+
return Job.objects.waiting().count()
107+
108+
109+
class RunningJobsCard(Card):
110+
title = "Running Jobs"
111+
112+
def get_number(self):
113+
return Job.objects.running().count()
114+
115+
102116
@register_viewset
103117
class JobRequestViewset(AdminModelViewset):
104118
class ListView(AdminModelListView):
@@ -117,6 +131,10 @@ class ListView(AdminModelListView):
117131
model = Job
118132
fields = ["id", "job_class", "priority", "created_at", "started_at"]
119133
actions = ["Delete"]
134+
cards = [
135+
WaitingJobsCard,
136+
RunningJobsCard,
137+
]
120138

121139
def perform_action(self, action: str, target_pks: list):
122140
if action == "Delete":

bolt-jobs/bolt/jobs/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ def convert_to_job(self, *, worker_uuid=None):
8686

8787

8888
class JobQuerySet(models.QuerySet):
89+
def running(self):
90+
return self.filter(started_at__isnull=False)
91+
92+
def waiting(self):
93+
return self.filter(started_at__isnull=True)
94+
8995
def mark_lost_jobs(self):
9096
# Lost jobs are jobs that have been pending for too long,
9197
# and probably never going to get picked up by a worker process.

0 commit comments

Comments
 (0)