Remove all methods no longer used now that we only send pdf files to DVLA.

This commit is contained in:
Rebecca Law
2018-02-28 11:42:23 +00:00
parent 304f4d5c67
commit bffc4863db
8 changed files with 24 additions and 181 deletions

View File

@@ -12,7 +12,6 @@ from notifications_utils.statsd_decorators import statsd
from notifications_utils.template import (
SMSMessageTemplate,
WithSubjectTemplate,
LetterDVLATemplate
)
from requests import (
HTTPError,
@@ -386,20 +385,6 @@ def update_letter_notifications_to_error(self, notification_references):
current_app.logger.debug("Updated {} letter notifications to technical-failure".format(updated_count))
def create_dvla_file_contents_for_notifications(notifications):
file_contents = '\n'.join(
str(LetterDVLATemplate(
notification.template.__dict__,
notification.personalisation,
notification_reference=notification.reference,
contact_block=notification.reply_to_text,
org_id=notification.service.dvla_organisation.id,
))
for notification in notifications
)
return file_contents
def handle_exception(task, notification, notification_id, exc):
if not get_notification_by_id(notification_id):
retry_msg = '{task} notification for job {job} row number {row} and notification id {noti}'.format(

View File

@@ -54,7 +54,6 @@ class QueueNames(object):
class TaskNames(object):
DVLA_JOBS = 'send-jobs-to-dvla'
DVLA_NOTIFICATIONS = 'send-api-notifications-to-dvla'
PROCESS_INCOMPLETE_JOBS = 'process-incomplete-jobs'
ZIP_AND_SEND_LETTER_PDFS = 'zip-and-send-letter-pdfs'

View File

@@ -3,14 +3,24 @@ from datetime import datetime, timedelta
from flask import current_app
from notifications_utils.statsd_decorators import statsd
from sqlalchemy import func, desc, asc, cast, Date as sql_date
from sqlalchemy import (
Date as sql_date,
asc,
cast,
desc,
func,
)
from app import db
from app.dao import days_ago
from app.models import (
Job, JobStatistics, Notification, NotificationHistory, Template,
JOB_STATUS_SCHEDULED, JOB_STATUS_PENDING,
LETTER_TYPE
Job,
JobStatistics,
JOB_STATUS_PENDING,
JOB_STATUS_SCHEDULED,
LETTER_TYPE,
NotificationHistory,
Template,
)
from app.variables import LETTER_TEST_API_FILENAME
@@ -22,28 +32,15 @@ def dao_get_notification_outcomes_for_job(service_id, job_id):
NotificationHistory.status
)
return query \
.filter(NotificationHistory.service_id == service_id) \
.filter(NotificationHistory.job_id == job_id)\
.group_by(NotificationHistory.status) \
.order_by(asc(NotificationHistory.status)) \
.all()
@statsd(namespace="dao")
def all_notifications_are_created_for_job(job_id):
query = db.session.query(func.count(Notification.id), Job.id)\
.join(Job)\
.filter(Job.id == job_id)\
.group_by(Job.id)\
.having(func.count(Notification.id) == Job.notification_count).all()
return query
@statsd(namespace="dao")
def dao_get_all_notifications_for_job(job_id):
return db.session.query(Notification).filter(Notification.job_id == job_id).order_by(Notification.created_at).all()
return query.filter(
NotificationHistory.service_id == service_id
).filter(
NotificationHistory.job_id == job_id
).group_by(
NotificationHistory.status
).order_by(
asc(NotificationHistory.status)
).all()
def dao_get_job_by_service_id_and_job_id(service_id, job_id):

View File

@@ -28,7 +28,6 @@ from app.models import (
NotificationHistory,
ScheduledNotification,
Service,
ServicePermission,
Template,
TemplateHistory,
KEY_TYPE_NORMAL,
@@ -547,42 +546,6 @@ def dao_get_total_notifications_sent_per_day_for_performance_platform(start_date
).one()
def dao_set_created_live_letter_api_notifications_to_pending():
"""
Sets all past scheduled jobs to pending, and then returns them for further processing.
this is used in the run_scheduled_jobs task, so we put a FOR UPDATE lock on the job table for the duration of
the transaction so that if the task is run more than once concurrently, one task will block the other select
from completing until it commits.
Note - do not process services that have letters_as_pdf permission as they
will get processed when the letters PDF zip task is created
"""
notifications = db.session.query(
Notification
).join(
Service
).filter(
Notification.notification_type == LETTER_TYPE,
Notification.status == NOTIFICATION_CREATED,
Notification.key_type == KEY_TYPE_NORMAL,
Notification.api_key != None, # noqa
# Ignore services that have letters_as_pdf permission
~Service.permissions.any(
ServicePermission.permission == 'letters_as_pdf'
)
).with_for_update(
).all()
for notification in notifications:
notification.status = NOTIFICATION_PENDING
db.session.add_all(notifications)
db.session.commit()
return notifications
@statsd(namespace="dao")
def dao_get_last_notification_added_for_job_id(job_id):
last_notification_added = Notification.query.filter(