Refactor code

- Created TaskNames for DVLA_FILES rather than have DVLA_FILES in QueueNames
- Removed PROCESS_FTP from all_queues() as this was causing problems in picking up letter job tasks
- Created test to ensure that we don't arbitrarily add queue names to all_queues
This commit is contained in:
Ken Tsang
2017-08-22 15:49:56 +01:00
parent 41fce57932
commit 4fb5e68ce7
5 changed files with 28 additions and 7 deletions

View File

@@ -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
)

View File

@@ -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']

View File

@@ -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