From e7e3c7d59ae98c6749da192a4a71cf73affd9377 Mon Sep 17 00:00:00 2001 From: Alex Parmentier Date: Tue, 1 Mar 2016 13:01:48 -0500 Subject: [PATCH] Fixed(?): Multiple celery workers. These changes should start up the workers to only take tasks from the correct queue, and should inform the django apps as to which queue to send tasks too. Obviously I won't know if this works until we try running it on the live server, but it seems to work locally (I can start multiple celery instances connected to the project, and only the one pointed at the correct queue will take the tasks) #210 --- celery_start_dev.sh | 2 +- celery_start_prod.sh | 2 +- elvis/settings.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/celery_start_dev.sh b/celery_start_dev.sh index fc0d3454..6ec5afc9 100755 --- a/celery_start_dev.sh +++ b/celery_start_dev.sh @@ -8,4 +8,4 @@ source ${VIRTUAL_ENV}/bin/activate # Move to project directory cd ${PROJECT_PATH} # Run your worker... old: exec celery worker -A elvis -l DEBUG --loglevel=INFO -exec celery worker -A elvis -l info --pidfile="/run/celery/%n-dev.pid" +exec celery worker -A elvis -l info --pidfile="/run/celery/%n-dev.pid" -Q elvis-dev diff --git a/celery_start_prod.sh b/celery_start_prod.sh index 0cbdcdd6..576d0d0a 100755 --- a/celery_start_prod.sh +++ b/celery_start_prod.sh @@ -8,4 +8,4 @@ source ${VIRTUAL_ENV}/bin/activate # Move to project directory cd ${PROJECT_PATH} # Run your worker... old: exec celery worker -A elvis -l DEBUG --loglevel=INFO -exec celery worker -A elvis -l info --pidfile="/run/celery/%n-prod.pid" +exec celery worker -A elvis -l info --pidfile="/run/celery/%n-prod.pid" -Q elvis-prod diff --git a/elvis/settings.py b/elvis/settings.py index 385cf2c6..7bd78b40 100644 --- a/elvis/settings.py +++ b/elvis/settings.py @@ -19,6 +19,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os import re +from kombu import Exchange, Queue BASE_DIR = os.path.abspath('./') @@ -259,14 +260,19 @@ CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT = ['json'] - +CELERY_QUEUE_DICT = {'queue': 'elvis-{}'.format(SETTING_TYPE)} +CELERY_ROUTES = {'elvis.zip_files': CELERY_QUEUE_DICT, + 'elvis.delete_zip_file': CELERY_QUEUE_DICT, + 'elvis.rebuild_suggesters': CELERY_QUEUE_DICT} # Elvis Web App Settings # ====================== ELVIS_EXTENSIONS = ['.xml', '.mxl', '.krn', '.md', '.nwc', '.tntxt', '.capx', '.abc', '.mid', '.midi', '.pdf', '.mei', '.ma', '.md2', '.json'] ELVIS_BAD_PREFIX = ['.', '..', '_', '__'] -SUGGEST_DICTS = ['composerSuggest', 'pieceSuggest', 'collectionSuggest', 'languageSuggest', 'genreSuggest', 'locationSuggest', 'sourceSuggest', 'instrumentSuggest', 'tagSuggest'] +SUGGEST_DICTS = ['composerSuggest', 'pieceSuggest', 'collectionSuggest', + 'languageSuggest', 'genreSuggest', 'locationSuggest', + 'sourceSuggest', 'instrumentSuggest', 'tagSuggest'] LOGGING = {