Merge branch 'master' into raise-400-for-validation-error

This commit is contained in:
Rebecca Law
2018-01-19 13:41:24 +00:00
committed by GitHub
4 changed files with 111 additions and 40 deletions

View File

@@ -120,7 +120,7 @@ def get_list_of_files_by_suffix(bucket_name, subfolder='', suffix='', last_modif
for page in page_iterator:
for obj in page.get('Contents', []):
key = obj['Key'].lower()
if key.endswith(suffix.lower()):
key = obj['Key']
if key.lower().endswith(suffix.lower()):
if not last_modified or obj['LastModified'] >= last_modified:
yield key

View File

@@ -337,6 +337,7 @@ def delete_dvla_response_files_older_than_seven_days():
@notify_celery.task(name="raise-alert-if-letter-notifications-still-sending")
@statsd(namespace="tasks")
def raise_alert_if_letter_notifications_still_sending():
today = datetime.utcnow().date()
# Do nothing on the weekend
@@ -356,15 +357,21 @@ def raise_alert_if_letter_notifications_still_sending():
).count()
if still_sending:
deskpro_client.create_ticket(
subject="Letters still sending",
message="There are {} letters in the 'sending' state from {}".format(
still_sending,
(today - timedelta(days=offset_days)).strftime('%A %d %B')
),
ticket_type="alert"
message = "There are {} letters in the 'sending' state from {}".format(
still_sending,
(today - timedelta(days=offset_days)).strftime('%A %d %B')
)
# Only send alerts in production
if current_app.config['NOTIFY_ENVIRONMENT'] in ['production', 'test']:
deskpro_client.create_ticket(
subject="[{}] Letters still sending".format(current_app.config['NOTIFY_ENVIRONMENT']),
message=message,
ticket_type="alert"
)
else:
current_app.logger.info(message)
@notify_celery.task(name="populate_monthly_billing")
@statsd(namespace="tasks")
@@ -487,40 +494,42 @@ def daily_stats_template_usage_by_month():
@statsd(namespace="tasks")
def letter_raise_alert_if_no_ack_file_for_zip():
# get a list of zip files since yesterday
zip_file_list = []
zip_file_set = set()
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'],
subfolder=datetime.utcnow().strftime('%Y-%m-%d'),
suffix='.zip'):
zip_file_list.append(key)
subfolder=datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent',
suffix='.TXT'):
zip_file_set.add(key.upper().rstrip('.TXT'))
# get acknowledgement file
ack_file_list = []
ack_file_set = set()
# yesterday = datetime.now(tz=pytz.utc) - timedelta(days=1)
yesterday = datetime.utcnow() - timedelta(days=1)
for key in s3.get_list_of_files_by_suffix(bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'],
subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday):
ack_file_list.append(key)
ack_file_set.add(key)
today_str = datetime.utcnow().strftime('%Y%m%d')
zip_not_today = []
for key in ack_file_list:
ack_content_set = set()
for key in ack_file_set:
if today_str in key:
content = s3.get_s3_file(current_app.config['DVLA_RESPONSE_BUCKET_NAME'], key)
for zip_file in content.split('\n'): # each line
s = zip_file.split('|')
for zf in zip_file_list:
if s[0].lower() in zf.lower():
zip_file_list.remove(zf)
else:
zip_not_today.append(s[0])
ack_content_set.add(s[0].upper())
if zip_file_list:
raise NoAckFileReceived(message=zip_file_list)
if zip_not_today:
current_app.logger.info(
"letter ack contains zip that is not for today {} ".format(zip_not_today)
if len(zip_file_set - ack_content_set) > 0:
deskpro_client.create_ticket(
subject="Letter acknowledge error",
message="Letter acknowledgement file do not contains all zip files sent: {}".format(datetime.utcnow()
.strftime('%Y-%m-%d')),
ticket_type='alert'
)
raise NoAckFileReceived(message=str(zip_file_set - ack_content_set))
if len(ack_content_set - zip_file_set) > 0:
current_app.logger.info(
"letter ack contains zip that is not for today: {}".format(ack_content_set - zip_file_set)
)