Skip to content

Commit

Permalink
Show waiting and running job stats
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jan 18, 2024
1 parent 1f901b3 commit 99eea5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bolt-jobs/bolt/jobs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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":
Expand Down
6 changes: 6 additions & 0 deletions bolt-jobs/bolt/jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 99eea5e

Please sign in to comment.