mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 17:23:50 -04:00
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:
@@ -1,4 +1,5 @@
|
||||
import dateutil
|
||||
import pytz
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
@@ -14,6 +15,7 @@ from app.dao.jobs_dao import (
|
||||
dao_get_jobs_by_service_id,
|
||||
dao_get_future_scheduled_job_by_id_and_service_id,
|
||||
dao_get_notification_outcomes_for_job,
|
||||
dao_get_scheduled_job_stats,
|
||||
dao_cancel_letter_job,
|
||||
can_letter_job_be_cancelled
|
||||
)
|
||||
@@ -188,6 +190,18 @@ def create_job(service_id):
|
||||
return jsonify(data=job_json), 201
|
||||
|
||||
|
||||
@job_blueprint.route('/scheduled-job-stats', methods=['GET'])
|
||||
def get_scheduled_job_stats(service_id):
|
||||
count, soonest_scheduled_for = dao_get_scheduled_job_stats(service_id)
|
||||
return jsonify(
|
||||
count=count,
|
||||
soonest_scheduled_for=(
|
||||
soonest_scheduled_for.replace(tzinfo=pytz.UTC).isoformat()
|
||||
if soonest_scheduled_for else None
|
||||
),
|
||||
), 200
|
||||
|
||||
|
||||
def get_paginated_jobs(
|
||||
service_id,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user