diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index e40021d38..5cc35f257 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -37,7 +37,7 @@ from app.models import LETTER_TYPE, JOB_STATUS_READY_TO_SEND from app.notifications.process_notifications import send_notification_to_queue from app.statsd_decorators import statsd from app.celery.tasks import process_job -from app.config import QueueNames +from app.config import QueueNames, TaskNames from app.utils import convert_utc_to_bst @@ -310,7 +310,7 @@ def populate_monthly_billing(): def run_letter_jobs(): job_ids = [job.id for job in dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)] notify_celery.send_task( - name=QueueNames.DVLA_FILES, + name=TaskNames.DVLA_FILES, args=(job_ids), queue=QueueNames.PROCESS_FTP ) diff --git a/app/config.py b/app/config.py index 2451c952d..1cb389eb3 100644 --- a/app/config.py +++ b/app/config.py @@ -30,7 +30,6 @@ class QueueNames(object): RETRY = 'retry-tasks' NOTIFY = 'notify-internal-tasks' PROCESS_FTP = 'process-ftp-tasks' - DVLA_FILES = 'send-files-to-dvla' @staticmethod def all_queues(): @@ -48,6 +47,10 @@ class QueueNames(object): ] +class TaskNames(object): + DVLA_FILES = 'send-files-to-dvla' + + class Config(object): # URL of admin app ADMIN_BASE_URL = os.environ['ADMIN_BASE_URL'] diff --git a/app/letters/rest.py b/app/letters/rest.py index ce43ea169..b9ce7bf35 100644 --- a/app/letters/rest.py +++ b/app/letters/rest.py @@ -2,7 +2,7 @@ from flask import Blueprint, jsonify from flask import request from app import notify_celery -from app.config import QueueNames +from app.config import QueueNames, TaskNames from app.dao.jobs_dao import dao_get_all_letter_jobs from app.schemas import job_schema from app.v2.errors import register_errors @@ -16,7 +16,7 @@ register_errors(letter_job) @letter_job.route('/send-letter-jobs', methods=['POST']) def send_letter_jobs(): job_ids = validate(request.get_json(), letter_job_ids) - notify_celery.send_task(name=QueueNames.DVLA_FILES, args=(job_ids['job_ids'],), queue=QueueNames.PROCESS_FTP) + notify_celery.send_task(name=TaskNames.DVLA_FILES, args=(job_ids['job_ids'],), queue=QueueNames.PROCESS_FTP) return jsonify(data={"response": "Task created to send files to DVLA"}), 201 diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 4d1be73ae..78d46a54b 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -31,7 +31,7 @@ from app.celery.scheduled_tasks import ( timeout_notifications, populate_monthly_billing) from app.clients.performance_platform.performance_platform_client import PerformancePlatformClient -from app.config import QueueNames +from app.config import QueueNames, TaskNames from app.dao.jobs_dao import dao_get_job_by_id from app.dao.notifications_dao import dao_get_scheduled_notifications from app.dao.provider_details_dao import ( @@ -695,6 +695,6 @@ def test_run_letter_jobs(client, mocker, sample_letter_template): run_letter_jobs() - mock_celery.assert_called_once_with(name=QueueNames.DVLA_FILES, + mock_celery.assert_called_once_with(name=TaskNames.DVLA_FILES, args=([job.id for job in jobs]), queue=QueueNames.PROCESS_FTP) diff --git a/tests/app/test_config.py b/tests/app/test_config.py index c1e1cbeee..fb251307b 100644 --- a/tests/app/test_config.py +++ b/tests/app/test_config.py @@ -5,6 +5,7 @@ from unittest import mock import pytest from app import config +from app.config import QueueNames def cf_conf(): @@ -57,3 +58,20 @@ def test_load_config_if_cloudfoundry_not_available(monkeypatch, reload_config): def test_cloudfoundry_config_has_different_defaults(): # these should always be set on Sandbox assert config.Sandbox.REDIS_ENABLED is False + + +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) == 10 + assert set([QueueNames.PRIORITY, + QueueNames.PERIODIC, + QueueNames.DATABASE, + QueueNames.SEND_SMS, + QueueNames.SEND_EMAIL, + QueueNames.RESEARCH_MODE, + QueueNames.STATISTICS, + QueueNames.JOBS, + QueueNames.RETRY, + QueueNames.NOTIFY + ]) == set(queues)