From 865cb6656e1d961d25f6063a11bb75da5f6e210c Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Thu, 3 Aug 2017 18:05:42 +0100 Subject: [PATCH] Allow for both an endpoint callback and SQS consumption --- app/celery/tasks.py | 7 +++++++ app/notifications/notifications_ses_callback.py | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index a042d7f0a..e4dcdafda 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -63,6 +63,7 @@ from app.models import ( SMS_TYPE, ) from app.notifications.process_notifications import persist_notification +from app.notifications.notifications_ses_callback import process_ses_response from app.service.utils import service_allowed_to_send_to from app.statsd_decorators import statsd from notifications_utils.s3 import s3upload @@ -547,3 +548,9 @@ def process_incomplete_job(job_id): process_row(row_number, recipient, personalisation, template, job, job.service) job_complete(job, job.service, template, resumed=True) + + +@notify_celery.task(bind=True, name='process-ses-result') +@statsd(namespace="tasks") +def process_ses_results(self, response): + process_ses_response(response) diff --git a/app/notifications/notifications_ses_callback.py b/app/notifications/notifications_ses_callback.py index b1d0ba589..101b6bbe1 100644 --- a/app/notifications/notifications_ses_callback.py +++ b/app/notifications/notifications_ses_callback.py @@ -27,11 +27,13 @@ register_errors(ses_callback_blueprint) @ses_callback_blueprint.route('/notifications/email/ses', methods=['POST']) -def process_ses_response(): +def sns_callback_handler(): + process_ses_response(json.loads(request.data)) + + +def process_ses_response(ses_request): client_name = 'SES' try: - ses_request = json.loads(request.data) - subscribed_topic = autoconfirm_subscription(ses_request) if subscribed_topic: current_app.logger.info("Automatically subscribed to topic: {}".format(subscribed_topic))