Fixes to the delete letter notifications.

If there are no files to delete we won't get an excpetion.
Wrap the delete file in a try/except to avoid stopping the entire task.
Fix the missing slash for the file name.
This commit is contained in:
Rebecca Law
2018-08-13 14:09:51 +01:00
parent bffef09d3d
commit f965322f25
3 changed files with 10 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ from datetime import (
date
)
from boto.exception import BotoClientError
from flask import current_app
from notifications_utils.recipients import (
@@ -345,7 +346,7 @@ def _delete_letters_from_s3(query):
if letter.sent_at:
sent_at = str(letter.sent_at.date())
prefix = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
folder=sent_at,
folder=sent_at + "/",
reference=letter.reference,
duplex="D",
letter_class="2",
@@ -355,7 +356,11 @@ def _delete_letters_from_s3(query):
).upper()[:-5]
s3_objects = get_s3_bucket_objects(bucket_name=bucket_name, subfolder=prefix)
for s3_object in s3_objects:
remove_s3_object(bucket_name, s3_object['Key'])
try:
remove_s3_object(bucket_name, s3_object['Key'])
except BotoClientError:
current_app.logger.exception(
"Could not delete S3 object with filename: {}".format(s3_object['Key']))
@statsd(namespace="dao")