mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
DRY-up conditionally creating callback tasks
This removes 3 duplicate instances of the same code, which is still
tested implicitly via test_process_ses_receipt_tasks [1]. In the
next commit we'll make this test more explicit, to reflect that it's
now being reused elsewhere and shouldn't change arbitrarily.
We do lose the "print" statement from the command instance of the
code, but I think that's a very tolerable loss.
[1]: 16ec8ccb8a/tests/app/celery/test_process_ses_receipts_tasks.py (L94)
This commit is contained in:
@@ -10,10 +10,6 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app import notify_celery, zendesk_client
|
||||
from app.aws import s3
|
||||
from app.celery.service_callback_tasks import (
|
||||
create_delivery_status_callback_data,
|
||||
send_delivery_status_to_service,
|
||||
)
|
||||
from app.config import QueueNames
|
||||
from app.cronitor import cronitor
|
||||
from app.dao.fact_processing_time_dao import insert_update_processing_time
|
||||
@@ -27,9 +23,6 @@ from app.dao.notifications_dao import (
|
||||
dao_timeout_notifications,
|
||||
delete_notifications_older_than_retention_by_type,
|
||||
)
|
||||
from app.dao.service_callback_api_dao import (
|
||||
get_service_delivery_status_callback_api_for_service,
|
||||
)
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
KEY_TYPE_NORMAL,
|
||||
@@ -39,6 +32,9 @@ from app.models import (
|
||||
FactProcessingTime,
|
||||
Notification,
|
||||
)
|
||||
from app.notifications.notifications_ses_callback import (
|
||||
check_and_queue_callback_task,
|
||||
)
|
||||
from app.utils import get_london_midnight_in_utc
|
||||
|
||||
|
||||
@@ -126,12 +122,7 @@ def timeout_notifications():
|
||||
dao_timeout_notifications(current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD'))
|
||||
|
||||
for notification in notifications:
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id) # noqa: E501
|
||||
if service_callback_api:
|
||||
encrypted_notification = create_delivery_status_callback_data(notification, service_callback_api)
|
||||
send_delivery_status_to_service.apply_async([str(notification.id), encrypted_notification],
|
||||
queue=QueueNames.CALLBACKS)
|
||||
check_and_queue_callback_task(notification)
|
||||
|
||||
current_app.logger.info(
|
||||
"Timeout period reached for {} notifications, status has been updated.".format(len(notifications)))
|
||||
|
||||
@@ -11,8 +11,8 @@ from app.config import QueueNames
|
||||
from app.dao import notifications_dao
|
||||
from app.models import NOTIFICATION_PENDING, NOTIFICATION_SENDING
|
||||
from app.notifications.notifications_ses_callback import (
|
||||
_check_and_queue_callback_task,
|
||||
_check_and_queue_complaint_callback_task,
|
||||
check_and_queue_callback_task,
|
||||
determine_notification_bounce_type,
|
||||
handle_complaint,
|
||||
)
|
||||
@@ -76,7 +76,7 @@ def process_ses_results(self, response):
|
||||
notification.sent_at
|
||||
)
|
||||
|
||||
_check_and_queue_callback_task(notification)
|
||||
check_and_queue_callback_task(notification)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -5,20 +5,15 @@ from flask import current_app
|
||||
from notifications_utils.template import SMSMessageTemplate
|
||||
|
||||
from app import notify_celery, statsd_client
|
||||
from app.celery.service_callback_tasks import (
|
||||
create_delivery_status_callback_data,
|
||||
send_delivery_status_to_service,
|
||||
)
|
||||
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.config import QueueNames
|
||||
from app.dao import notifications_dao
|
||||
from app.dao.service_callback_api_dao import (
|
||||
get_service_delivery_status_callback_api_for_service,
|
||||
)
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import NOTIFICATION_PENDING
|
||||
from app.notifications.notifications_ses_callback import (
|
||||
check_and_queue_callback_task,
|
||||
)
|
||||
|
||||
sms_response_mapper = {
|
||||
'MMG': get_mmg_responses,
|
||||
@@ -94,9 +89,4 @@ def _process_for_status(notification_status, client_name, provider_reference, de
|
||||
notifications_dao.dao_update_notification(notification)
|
||||
|
||||
if notification_status != NOTIFICATION_PENDING:
|
||||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id)
|
||||
# queue callback task only if the service_callback_api exists
|
||||
if service_callback_api:
|
||||
encrypted_notification = create_delivery_status_callback_data(notification, service_callback_api)
|
||||
send_delivery_status_to_service.apply_async([str(notification.id), encrypted_notification],
|
||||
queue=QueueNames.CALLBACKS)
|
||||
check_and_queue_callback_task(notification)
|
||||
|
||||
Reference in New Issue
Block a user