Add an endpoint for stats about scheduled jobs

At the moment we display the count of scheduled jobs on the dashboard
by sending all the scheduled jobs to the admin app and letting it work
out the stats.

This is inefficient and, because the get jobs response has a page size
of 50, becomes incorrect if a service schedules more than 50 jobs.

This commit adds a separate endpoint which gives the admin app the stats
it needs directly and correctly.
This commit is contained in:
Chris Hill-Scott
2020-09-28 09:57:32 +01:00
parent f651176343
commit 2fcde009ac
3 changed files with 59 additions and 0 deletions

View File

@@ -84,6 +84,18 @@ def dao_get_jobs_by_service_id(
.paginate(page=page, per_page=page_size)
def dao_get_scheduled_job_stats(
service_id,
):
return db.session.query(
func.count(Job.id),
func.min(Job.scheduled_for),
).filter(
Job.service_id == service_id,
Job.job_status == JOB_STATUS_SCHEDULED,
).one()
def dao_get_job_by_id(job_id):
return Job.query.filter_by(id=job_id).one()