mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Added a jobs_dao method to answer if the all the notifications have been created in the database for the given job.
This commit is contained in:
@@ -5,7 +5,11 @@ from sqlalchemy import func, desc, asc, cast, Date as sql_date
|
||||
|
||||
from app import db
|
||||
from app.dao import days_ago
|
||||
from app.models import Job, NotificationHistory, JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING
|
||||
from app.models import (Job,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
JOB_STATUS_SCHEDULED,
|
||||
JOB_STATUS_PENDING)
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -24,6 +28,20 @@ def dao_get_notification_outcomes_for_job(service_id, job_id):
|
||||
.all()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def are_all_notifications_created_for_job(job_id):
|
||||
query = db.session.query(func.count(Notification.id))\
|
||||
.join(Job)\
|
||||
.filter(Job.id == job_id)\
|
||||
.group_by(Job.id)\
|
||||
.having(func.count(Notification.id) == Job.notification_count).first()
|
||||
|
||||
if query:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def dao_get_job_by_service_id_and_job_id(service_id, job_id):
|
||||
return Job.query.filter_by(service_id=service_id, id=job_id).one()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user