Group the letters by postage class.

In this PR the letters are grouped and sent by postage type.
This means we can group the first class letters first and start sending them.

This PR is to share an idea... tests have not been written and an order to postage hasn't been added. There is also a PR in the works to add the new postage classes so we should consider that.
This commit is contained in:
Rebecca Law
2020-03-19 09:32:50 +00:00
parent 67339d7fd9
commit 9dc9431550
2 changed files with 33 additions and 31 deletions
+6 -5
View File
@@ -52,7 +52,7 @@ from app.models import (
NOTIFICATION_TECHNICAL_FAILURE, NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_VALIDATION_FAILED, NOTIFICATION_VALIDATION_FAILED,
NOTIFICATION_VIRUS_SCAN_FAILED, NOTIFICATION_VIRUS_SCAN_FAILED,
) POSTAGE_TYPES)
from app.cronitor import cronitor from app.cronitor import cronitor
@@ -136,7 +136,8 @@ def collate_letter_pdfs_to_be_sent():
hour=17, minute=30, second=0, microsecond=0 hour=17, minute=30, second=0, microsecond=0
) )
letters_to_print = get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline) for postage in POSTAGE_TYPES:
letters_to_print = get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline, postage)
for i, letters in enumerate(group_letters(letters_to_print)): for i, letters in enumerate(group_letters(letters_to_print)):
filenames = [letter['Key'] for letter in letters] filenames = [letter['Key'] for letter in letters]
@@ -167,8 +168,8 @@ def collate_letter_pdfs_to_be_sent():
) )
def get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline): def get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline, postage):
letters_awaiting_sending = dao_get_letters_to_be_printed(print_run_deadline) letters_awaiting_sending = dao_get_letters_to_be_printed(print_run_deadline, postage)
letter_pdfs = [] letter_pdfs = []
for letter in letters_awaiting_sending: for letter in letters_awaiting_sending:
@@ -183,7 +184,7 @@ def get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline):
letter_pdfs.append({"Key": letter_file_name, "Size": letter_head['ContentLength']}) letter_pdfs.append({"Key": letter_file_name, "Size": letter_head['ContentLength']})
except BotoClientError as e: except BotoClientError as e:
current_app.logger.exception( current_app.logger.exception(
f"Error getting letter from bucket for notification: {letter.id} with reference: {letter.reference}", e) f"Error getting letter from bucket for notification: {letter.id} with reference: {letter.reference}")
return letter_pdfs return letter_pdfs
+3 -2
View File
@@ -731,7 +731,7 @@ def notifications_not_yet_sent(should_be_sending_after_seconds, notification_typ
return notifications return notifications
def dao_get_letters_to_be_printed(print_run_deadline): def dao_get_letters_to_be_printed(print_run_deadline, postage):
""" """
Return all letters created before the print run deadline that have not yet been sent Return all letters created before the print run deadline that have not yet been sent
""" """
@@ -739,7 +739,8 @@ def dao_get_letters_to_be_printed(print_run_deadline):
Notification.created_at < convert_bst_to_utc(print_run_deadline), Notification.created_at < convert_bst_to_utc(print_run_deadline),
Notification.notification_type == LETTER_TYPE, Notification.notification_type == LETTER_TYPE,
Notification.status == NOTIFICATION_CREATED, Notification.status == NOTIFICATION_CREATED,
Notification.key_type == KEY_TYPE_NORMAL Notification.key_type == KEY_TYPE_NORMAL,
Notification.postage == postage
).order_by( ).order_by(
Notification.created_at Notification.created_at
).all() ).all()