implement SNS

This commit is contained in:
Jim Moffet
2022-06-17 11:16:23 -07:00
parent 79ba6cc1d1
commit aa4ec532a4
17 changed files with 218 additions and 351 deletions

View File

@@ -6,8 +6,6 @@ from notifications_utils.template import SMSMessageTemplate
from app import notify_celery, statsd_client
from app.clients import ClientException
from app.clients.sms.firetext import get_firetext_responses
from app.clients.sms.mmg import get_mmg_responses
from app.dao import notifications_dao
from app.dao.templates_dao import dao_get_template_by_id
from app.models import NOTIFICATION_PENDING
@@ -15,44 +13,44 @@ from app.notifications.notifications_ses_callback import (
check_and_queue_callback_task,
)
sms_response_mapper = {
'MMG': get_mmg_responses,
'Firetext': get_firetext_responses,
}
# sms_response_mapper = {
# 'MMG': get_mmg_responses,
# 'Firetext': get_firetext_responses,
# }
@notify_celery.task(bind=True, name="process-sms-client-response", max_retries=5, default_retry_delay=300)
def process_sms_client_response(self, status, provider_reference, client_name, detailed_status_code=None):
# validate reference
try:
uuid.UUID(provider_reference, version=4)
except ValueError as e:
current_app.logger.exception(f'{client_name} callback with invalid reference {provider_reference}')
raise e
# @notify_celery.task(bind=True, name="process-sms-client-response", max_retries=5, default_retry_delay=300)
# def process_sms_client_response(self, status, provider_reference, client_name, detailed_status_code=None):
# # validate reference
# try:
# uuid.UUID(provider_reference, version=4)
# except ValueError as e:
# current_app.logger.exception(f'{client_name} callback with invalid reference {provider_reference}')
# raise e
response_parser = sms_response_mapper[client_name]
# response_parser = sms_response_mapper[client_name]
# validate status
try:
notification_status, detailed_status = response_parser(status, detailed_status_code)
current_app.logger.info(
f'{client_name} callback returned status of {notification_status}'
f'({status}): {detailed_status}({detailed_status_code}) for reference: {provider_reference}'
)
except KeyError:
_process_for_status(
notification_status='technical-failure',
client_name=client_name,
provider_reference=provider_reference
)
raise ClientException(f'{client_name} callback failed: status {status} not found.')
# # validate status
# try:
# notification_status, detailed_status = response_parser(status, detailed_status_code)
# current_app.logger.info(
# f'{client_name} callback returned status of {notification_status}'
# f'({status}): {detailed_status}({detailed_status_code}) for reference: {provider_reference}'
# )
# except KeyError:
# _process_for_status(
# notification_status='technical-failure',
# client_name=client_name,
# provider_reference=provider_reference
# )
# raise ClientException(f'{client_name} callback failed: status {status} not found.')
_process_for_status(
notification_status=notification_status,
client_name=client_name,
provider_reference=provider_reference,
detailed_status_code=detailed_status_code
)
# _process_for_status(
# notification_status=notification_status,
# client_name=client_name,
# provider_reference=provider_reference,
# detailed_status_code=detailed_status_code
# )
def _process_for_status(notification_status, client_name, provider_reference, detailed_status_code=None):