mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
If there is an invalid letter that has not been updated to validation-failed because the update-validation-failed-for-templated-letter has not been picked up off the letter-tasks queue and the collate-letter-pdfs-to-be-sent has started.
1. The number of letters that we send to DVLA will be not be correct (see20ead82463/app/celery/letters_pdf_tasks.py (L136)) This may raise an alert with DVLA when they find we have sent them fewer letter than we have reported. 2. When we get the PDF from S3 we will get a file not found20ead82463/app/celery/letters_pdf_tasks.py (L244)The error will not prevent the collate task from completing but we will see an alert email for the exception and raise questions. Although this situation is very unlikely because we have a 15 minute window between the last letter deadline date and the time we kick off the collate task we should still mitigate these issues. I updated the queries to only return letters with billable_units > 0, all valid letters should have at least 1 billable unit.
This commit is contained in:
@@ -4,7 +4,6 @@ from hashlib import sha512
|
||||
|
||||
from botocore.exceptions import ClientError as BotoClientError
|
||||
from flask import current_app
|
||||
from notifications_utils import LETTER_MAX_PAGE_COUNT
|
||||
from notifications_utils.letter_timings import LETTER_PROCESSING_DEADLINE
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
@@ -102,27 +101,30 @@ def get_pdf_for_templated_letter(self, notification_id):
|
||||
|
||||
|
||||
@notify_celery.task(bind=True, name="update-billable-units-for-letter", max_retries=15, default_retry_delay=300)
|
||||
def update_billable_units_or_validation_failed_for_templated_letter(self, notification_id, page_count,
|
||||
create_fake_letter_response_file=None):
|
||||
def update_billable_units_for_letter(self, notification_id, page_count):
|
||||
notification = get_notification_by_id(notification_id, _raise=True)
|
||||
if page_count > LETTER_MAX_PAGE_COUNT:
|
||||
notification.status = NOTIFICATION_VALIDATION_FAILED
|
||||
|
||||
billable_units = get_billable_units_for_letter_page_count(page_count)
|
||||
|
||||
if notification.key_type != KEY_TYPE_TEST:
|
||||
notification.billable_units = billable_units
|
||||
dao_update_notification(notification)
|
||||
current_app.logger.info(f"Letter notification id: {notification_id} reference {notification.reference}: "
|
||||
f"validation failed: letter is too long {page_count}")
|
||||
else:
|
||||
if notification.key_type != KEY_TYPE_TEST:
|
||||
notification.billable_units = get_billable_units_for_letter_page_count(page_count)
|
||||
dao_update_notification(notification)
|
||||
current_app.logger.info(f"Letter notification id: {notification_id} reference {notification.reference}: "
|
||||
f"billable units set to {notification.billable_units}")
|
||||
if notification.key_type == KEY_TYPE_TEST \
|
||||
and current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']:
|
||||
# For test letters send a fake letter response
|
||||
create_fake_letter_response_file.apply_async(
|
||||
(notification.reference,),
|
||||
queue=QueueNames.RESEARCH_MODE
|
||||
)
|
||||
|
||||
current_app.logger.info(
|
||||
f"Letter notification id: {notification_id} reference {notification.reference}: "
|
||||
f"billable units set to {billable_units}"
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(
|
||||
bind=True, name="update-validation-failed-for-templated-letter", max_retries=15, default_retry_delay=300
|
||||
)
|
||||
def update_validation_failed_for_templated_letter(self, notification_id, page_count):
|
||||
notification = get_notification_by_id(notification_id, _raise=True)
|
||||
notification.status = NOTIFICATION_VALIDATION_FAILED
|
||||
dao_update_notification(notification)
|
||||
current_app.logger.info(f"Letter notification id: {notification_id} reference {notification.reference}: "
|
||||
f"validation failed: letter is too long {page_count}")
|
||||
|
||||
|
||||
@notify_celery.task(name='collate-letter-pdfs-to-be-sent')
|
||||
|
||||
@@ -711,7 +711,8 @@ def dao_get_letters_to_be_printed(print_run_deadline, postage, query_limit=10000
|
||||
Notification.notification_type == LETTER_TYPE,
|
||||
Notification.status == NOTIFICATION_CREATED,
|
||||
Notification.key_type == KEY_TYPE_NORMAL,
|
||||
Notification.postage == postage
|
||||
Notification.postage == postage,
|
||||
Notification.billable_units > 0
|
||||
).order_by(
|
||||
Notification.service_id,
|
||||
Notification.created_at
|
||||
@@ -729,6 +730,7 @@ def dao_get_letters_and_sheets_volume_by_postage(print_run_deadline):
|
||||
Notification.notification_type == LETTER_TYPE,
|
||||
Notification.status == NOTIFICATION_CREATED,
|
||||
Notification.key_type == KEY_TYPE_NORMAL,
|
||||
Notification.billable_units > 0
|
||||
).group_by(
|
||||
Notification.postage
|
||||
).order_by(
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.celery.letters_pdf_tasks import (
|
||||
get_pdf_for_templated_letter,
|
||||
sanitise_letter,
|
||||
)
|
||||
from app.celery.research_mode_tasks import create_fake_letter_response_file
|
||||
from app.celery.tasks import save_api_email, save_api_sms
|
||||
from app.clients.document_download import DocumentDownloadError
|
||||
from app.config import QueueNames, TaskNames
|
||||
@@ -388,6 +389,12 @@ def process_letter_notification(
|
||||
queue=queue
|
||||
)
|
||||
|
||||
if test_key and current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']:
|
||||
create_fake_letter_response_file.apply_async(
|
||||
(notification.reference,),
|
||||
queue=queue
|
||||
)
|
||||
|
||||
resp = create_response_for_post_notification(
|
||||
notification_id=notification.id,
|
||||
client_reference=notification.client_reference,
|
||||
|
||||
Reference in New Issue
Block a user