From cb3ef9c47536212b0a2ed3de77c0c5a96f16be46 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Mon, 16 Dec 2024 16:57:20 -0500 Subject: [PATCH] wip contact_information_tasks status and status_reasons --- app/celery/contact_information_tasks.py | 14 +++++--------- app/va/va_profile/exceptions.py | 17 +++++++++++++++++ .../celery/test_contact_information_tasks.py | 17 ++++++++--------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/celery/contact_information_tasks.py b/app/celery/contact_information_tasks.py index b220c4cb6c..e132e4f269 100644 --- a/app/celery/contact_information_tasks.py +++ b/app/celery/contact_information_tasks.py @@ -142,9 +142,7 @@ def handle_lookup_contact_info_exception( ) current_app.logger.info('%s - %s: %s', e.__class__.__name__, str(e), message) - update_notification_status_by_id( - notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=e.failure_reason - ) + update_notification_status_by_id(notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=e.status_reason) check_and_queue_callback_task(notification) # Expected chain termination lookup_task.request.chain = None @@ -154,9 +152,7 @@ def handle_lookup_contact_info_exception( 'Notification has been updated to permanent-failure' ) current_app.logger.info(message) - update_notification_status_by_id( - notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=e.failure_reason - ) + update_notification_status_by_id(notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=e.status_reason) check_and_queue_callback_task(notification) # Expected chain termination lookup_task.request.chain = None @@ -168,9 +164,9 @@ def handle_lookup_contact_info_exception( ) if not notification.default_send: update_notification_status_by_id( - notification_id=notification.id, - status=NOTIFICATION_PERMANENT_FAILURE, - status_reason='No recipient opt-in found for explicit preference', + notification.id, + NOTIFICATION_PERMANENT_FAILURE, + status_reason=e.status_reason, ) check_and_queue_callback_task(notification) # Expected chain termination diff --git a/app/va/va_profile/exceptions.py b/app/va/va_profile/exceptions.py index cd85ef4356..a61f6c1bcb 100644 --- a/app/va/va_profile/exceptions.py +++ b/app/va/va_profile/exceptions.py @@ -1,34 +1,51 @@ +from app.constants import ( + STATUS_REASON_DECLINED, + STATUS_REASON_NO_CONTACT, + STATUS_REASON_NO_ID_FOUND, + STATUS_REASON_NO_PROFILE, + STATUS_REASON_RETRYABLE, +) + + class VAProfileException(Exception): pass class VAProfileIdNotFoundException(VAProfileException): failure_reason = 'No VA Profile Id was found' + status_reason = STATUS_REASON_NO_ID_FOUND class VAProfileRetryableException(VAProfileException): failure_reason = 'Retryable VAProfile error occurred' + status_reason = STATUS_REASON_RETRYABLE class VAProfileNonRetryableException(VAProfileException): failure_reason = 'Non-retryable VAProfile error occurred' + status_reason = STATUS_REASON_NO_PROFILE class NoContactInfoException(VAProfileNonRetryableException): failure_reason = 'No contact info found from VA Profile' + status_reason = STATUS_REASON_NO_CONTACT class InvalidPhoneNumberException(VAProfileNonRetryableException): failure_reason = 'Phone number is invalid' + status_reason = STATUS_REASON_NO_CONTACT class VAProfileIDNotFoundException(VAProfileNonRetryableException): failure_reason = 'No VA Profile account found' + status_reason = STATUS_REASON_NO_PROFILE class ContactPreferencesException(VAProfileNonRetryableException): failure_reason = 'VA Profile contact preferences not allowing contact' + status_reason = STATUS_REASON_DECLINED class CommunicationItemNotFoundException(VAProfileNonRetryableException): failure_reason = 'No communication bio found from VA Profile' + status_reason = STATUS_REASON_DECLINED diff --git a/tests/app/celery/test_contact_information_tasks.py b/tests/app/celery/test_contact_information_tasks.py index 0d1803f59e..0803d35326 100644 --- a/tests/app/celery/test_contact_information_tasks.py +++ b/tests/app/celery/test_contact_information_tasks.py @@ -3,10 +3,9 @@ import pytest from requests import Timeout -from app.celery.common import RETRIES_EXCEEDED from app.celery.contact_information_tasks import lookup_contact_info from app.celery.exceptions import AutoRetryException -from app.constants import EMAIL_TYPE, NOTIFICATION_PERMANENT_FAILURE, NOTIFICATION_TECHNICAL_FAILURE, SMS_TYPE +from app.constants import EMAIL_TYPE, NOTIFICATION_PERMANENT_FAILURE, SMS_TYPE, STATUS_REASON_UNDELIVERABLE from app.exceptions import NotificationTechnicalFailureException from app.models import RecipientIdentifier from app.va.identifier import IdentifierType @@ -138,7 +137,7 @@ def test_should_not_retry_on_non_retryable_exception(client, mocker, sample_temp assert recipient_identifier.id_value == EXAMPLE_VA_PROFILE_ID mocked_update_notification_status_by_id.assert_called_with( - notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=exception.failure_reason + notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=exception.status_reason ) mocked_check_and_queue_callback_task.assert_called_once_with(notification) @@ -264,7 +263,7 @@ def test_should_update_notification_to_permanent_failure_on_no_contact_info_exce assert recipient_identifier.id_value == EXAMPLE_VA_PROFILE_ID mocked_update_notification_status_by_id.assert_called_with( - notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=exception.failure_reason + notification.id, NOTIFICATION_PERMANENT_FAILURE, status_reason=exception.status_reason ) mocked_check_and_queue_callback_task.assert_called_once_with(notification) @@ -276,20 +275,20 @@ def test_should_update_notification_to_permanent_failure_on_no_contact_info_exce ( VAProfileRetryableException, NotificationTechnicalFailureException, - NOTIFICATION_TECHNICAL_FAILURE, - RETRIES_EXCEEDED, + NOTIFICATION_PERMANENT_FAILURE, + STATUS_REASON_UNDELIVERABLE, ), ( NoContactInfoException, None, NOTIFICATION_PERMANENT_FAILURE, - NoContactInfoException.failure_reason, + NoContactInfoException.status_reason, ), ( VAProfileNonRetryableException, None, NOTIFICATION_PERMANENT_FAILURE, - VAProfileNonRetryableException.failure_reason, + VAProfileNonRetryableException.status_reason, ), ], ) @@ -319,7 +318,7 @@ def test_exception_sets_failure_reason_if_thrown( 'app.celery.contact_information_tasks.check_and_queue_callback_task', ) - if exception_reason == RETRIES_EXCEEDED: + if exception == VAProfileRetryableException: mocker_handle_max_retries_exceeded = mocker.patch( 'app.celery.contact_information_tasks.handle_max_retries_exceeded' )