From cef8d6e29425a583c45a216e4752730e4dd5e53b Mon Sep 17 00:00:00 2001 From: venusbb Date: Wed, 13 Dec 2017 11:55:08 +0000 Subject: [PATCH] use callback queue --- app/celery/scheduled_tasks.py | 2 +- app/celery/tasks.py | 4 ++-- app/notifications/notifications_ses_callback.py | 2 +- app/notifications/process_client_response.py | 2 +- tests/app/celery/test_ftp_update_tasks.py | 4 ++-- tests/app/notifications/test_notifications_ses_callback.py | 2 +- tests/app/notifications/test_process_client_response.py | 2 +- tests/app/test_config.py | 5 +++-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index ed14be2e4..7b28b0fb4 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -199,7 +199,7 @@ def timeout_notifications(): service_callback_api = get_service_callback_api_for_service(service_id=notification.service_id) if service_callback_api: - send_delivery_status_to_service.apply_async([str(id)], queue=QueueNames.NOTIFY) + send_delivery_status_to_service.apply_async([str(id)], queue=QueueNames.CALLBACKS) current_app.logger.info( "Timeout period reached for {} notifications, status has been updated.".format(len(notifications))) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index 8657cfb5a..7460f3b90 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -416,7 +416,7 @@ def update_letter_notifications_to_error(self, notification_references): service_callback_api = get_service_callback_api_for_service(service_id=notifications[0].service_id) if service_callback_api: for notification in notifications: - send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY) + send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.CALLBACKS) def create_dvla_file_contents_for_job(job_id): @@ -503,7 +503,7 @@ def update_letter_notifications_statuses(self, filename): service_callback_api = get_service_callback_api_for_service(service_id=notifications[0].service_id) if service_callback_api: for notification in notifications: - send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY) + send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.CALLBACKS) def process_updates_from_file(response_file): diff --git a/app/notifications/notifications_ses_callback.py b/app/notifications/notifications_ses_callback.py index 28fa96f2e..cf3da7508 100644 --- a/app/notifications/notifications_ses_callback.py +++ b/app/notifications/notifications_ses_callback.py @@ -99,4 +99,4 @@ def _check_and_queue_callback_task(notification_id, service_id): # queue callback task only if the service_callback_api exists service_callback_api = get_service_callback_api_for_service(service_id=service_id) if service_callback_api: - send_delivery_status_to_service.apply_async([str(notification_id)], queue=QueueNames.NOTIFY) + send_delivery_status_to_service.apply_async([str(notification_id)], queue=QueueNames.CALLBACKS) diff --git a/app/notifications/process_client_response.py b/app/notifications/process_client_response.py index ed825766a..ad78c744d 100644 --- a/app/notifications/process_client_response.py +++ b/app/notifications/process_client_response.py @@ -89,7 +89,7 @@ def process_sms_client_response(status, reference, client_name): service_callback_api = get_service_callback_api_for_service(service_id=notification.service_id) if service_callback_api: - send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY) + send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.CALLBACKS) success = "{} callback succeeded. reference {} updated".format(client_name, reference) return success, errors diff --git a/tests/app/celery/test_ftp_update_tasks.py b/tests/app/celery/test_ftp_update_tasks.py index 2c6bc4393..cf3e90ade 100644 --- a/tests/app/celery/test_ftp_update_tasks.py +++ b/tests/app/celery/test_ftp_update_tasks.py @@ -116,8 +116,8 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp assert failed_letter.billable_units == 2 assert failed_letter.updated_at - calls = [call([str(failed_letter.id)], queue="notify-internal-tasks"), - call([str(sent_letter.id)], queue="notify-internal-tasks")] + calls = [call([str(failed_letter.id)], queue="service-callbacks"), + call([str(sent_letter.id)], queue="service-callbacks")] send_mock.assert_has_calls(calls, any_order=True) diff --git a/tests/app/notifications/test_notifications_ses_callback.py b/tests/app/notifications/test_notifications_ses_callback.py index 49ce90829..157b22ae3 100644 --- a/tests/app/notifications/test_notifications_ses_callback.py +++ b/tests/app/notifications/test_notifications_ses_callback.py @@ -47,7 +47,7 @@ def test_ses_callback_should_update_notification_status( ) statsd_client.incr.assert_any_call("callback.ses.delivered") stats_mock.assert_called_once_with(notification) - send_mock.assert_called_once_with([str(notification.id)], queue="notify-internal-tasks") + send_mock.assert_called_once_with([str(notification.id)], queue="service-callbacks") def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry( diff --git a/tests/app/notifications/test_process_client_response.py b/tests/app/notifications/test_process_client_response.py index 40e2a608c..3f49901dd 100644 --- a/tests/app/notifications/test_process_client_response.py +++ b/tests/app/notifications/test_process_client_response.py @@ -61,7 +61,7 @@ def test_outcome_statistics_called_for_successful_callback(sample_notification, success, error = process_sms_client_response(status='3', reference=reference, client_name='MMG') assert success == "MMG callback succeeded. reference {} updated".format(str(reference)) assert error is None - send_mock.assert_called_once_with([str(sample_notification.id)], queue="notify-internal-tasks") + send_mock.assert_called_once_with([str(sample_notification.id)], queue="service-callbacks") stats_mock.assert_called_once_with(sample_notification) diff --git a/tests/app/test_config.py b/tests/app/test_config.py index c023fa37a..2f643ba5c 100644 --- a/tests/app/test_config.py +++ b/tests/app/test_config.py @@ -63,7 +63,7 @@ def test_cloudfoundry_config_has_different_defaults(): def test_queue_names_all_queues_correct(): # Need to ensure that all_queues() only returns queue names used in API queues = QueueNames.all_queues() - assert len(queues) == 11 + assert len(queues) == 12 assert set([ QueueNames.PRIORITY, QueueNames.PERIODIC, @@ -75,5 +75,6 @@ def test_queue_names_all_queues_correct(): QueueNames.JOBS, QueueNames.RETRY, QueueNames.NOTIFY, - QueueNames.CREATE_LETTERS_PDF + QueueNames.CREATE_LETTERS_PDF, + QueueNames.CALLBACKS ]) == set(queues)