Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-report-tasks

This commit is contained in:
venusbb
2018-03-28 10:53:45 +01:00
7 changed files with 132 additions and 36 deletions

View File

@@ -22,16 +22,16 @@ from app.dao.notifications_dao import (
dao_update_notifications_by_reference,
)
from app.letters.utils import (
delete_pdf_from_letters_scan_bucket,
get_reference_from_filename,
move_scanned_pdf_to_test_or_live_pdf_bucket,
upload_letter_pdf
)
upload_letter_pdf,
move_failed_pdf, ScanErrorType)
from app.models import (
KEY_TYPE_TEST,
NOTIFICATION_CREATED,
NOTIFICATION_DELIVERED,
NOTIFICATION_VIRUS_SCAN_FAILED,
NOTIFICATION_TECHNICAL_FAILURE
)
@@ -180,7 +180,7 @@ def process_virus_scan_passed(filename):
@notify_celery.task(name='process-virus-scan-failed')
def process_virus_scan_failed(filename):
current_app.logger.exception('Virus scan failed: {}'.format(filename))
delete_pdf_from_letters_scan_bucket(filename)
move_failed_pdf(filename, ScanErrorType.FAILURE)
reference = get_reference_from_filename(filename)
updated_count = update_letter_pdf_status(reference, NOTIFICATION_VIRUS_SCAN_FAILED)
@@ -192,6 +192,21 @@ def process_virus_scan_failed(filename):
)
@notify_celery.task(name='process-virus-scan-error')
def process_virus_scan_error(filename):
current_app.logger.exception('Virus scan error: {}'.format(filename))
move_failed_pdf(filename, ScanErrorType.ERROR)
reference = get_reference_from_filename(filename)
updated_count = update_letter_pdf_status(reference, NOTIFICATION_TECHNICAL_FAILURE)
if updated_count != 1:
raise Exception(
"There should only be one letter notification for each reference. Found {} notifications".format(
updated_count
)
)
def update_letter_pdf_status(reference, status):
return dao_update_notifications_by_reference(
references=[reference],

View File

@@ -22,10 +22,10 @@ def worker_process_shutdown(sender, signal, pid, exitcode):
@statsd(namespace="tasks")
def deliver_sms(self, notification_id):
try:
current_app.logger.info("Start sending SMS for notification id: {}".format(notification_id))
notification = notifications_dao.get_notification_by_id(notification_id)
if not notification:
raise NoResultFound()
current_app.logger.info("Start sending SMS for notification id: {}".format(notification_id))
send_to_providers.send_sms_to_provider(notification)
except Exception as e:
try:
@@ -44,10 +44,10 @@ def deliver_sms(self, notification_id):
@statsd(namespace="tasks")
def deliver_email(self, notification_id):
try:
current_app.logger.info("Start sending email for notification id: {}".format(notification_id))
notification = notifications_dao.get_notification_by_id(notification_id)
if not notification:
raise NoResultFound()
current_app.logger.info("Start sending email for notification id: {}".format(notification_id))
send_to_providers.send_email_to_provider(notification)
except InvalidEmailError as e:
current_app.logger.exception(e)