Skip to content

Commit

Permalink
wip contact_information_tasks status and status_reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Johnson committed Dec 16, 2024
1 parent 0c450d9 commit cb3ef9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
14 changes: 5 additions & 9 deletions app/celery/contact_information_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions app/va/va_profile/exceptions.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 8 additions & 9 deletions tests/app/celery/test_contact_information_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
),
],
)
Expand Down Expand Up @@ -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'
)
Expand Down

0 comments on commit cb3ef9c

Please sign in to comment.