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:
Rebecca Law
2017-03-14 10:50:09 +00:00
parent 28249fb4e2
commit ea4214c7d5
2 changed files with 38 additions and 3 deletions

View File

@@ -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()