diff --git a/etc/systemd/system/pandora-encoding.service b/etc/systemd/system/pandora-encoding.service index f56f0eb2..8d5e3bda 100644 --- a/etc/systemd/system/pandora-encoding.service +++ b/etc/systemd/system/pandora-encoding.service @@ -8,9 +8,9 @@ Restart=always User=pandora Group=pandora PIDFile=/run/pandora/encoding.pid -WorkingDirectory=/srv/pandora/pandora -ExecStart=/srv/pandora/bin/python /srv/pandora/pandora/manage.py \ - celery worker \ +WorkingDirectory=/srv/pandora +ExecStart=/srv/pandora/bin/celery \ + -A pandora worker \ -Q encoding -n pandora-encoding \ --pidfile /run/pandora/encoding.pid \ --maxtasksperchild 500 \ diff --git a/etc/systemd/system/pandora-tasks.service b/etc/systemd/system/pandora-tasks.service index 5972e8b3..277a0072 100644 --- a/etc/systemd/system/pandora-tasks.service +++ b/etc/systemd/system/pandora-tasks.service @@ -9,8 +9,8 @@ User=pandora Group=pandora PIDFile=/run/pandora/tasks.pid WorkingDirectory=/srv/pandora/pandora -ExecStart=/srv/pandora/bin/python /srv/pandora/pandora/manage.py \ - celery worker \ +ExecStart=/srv/pandora/bin/celery \ + -A pandora worker \ -Q default,celery -n pandora-default \ --pidfile /run/pandora/tasks.pid \ --maxtasksperchild 1000 \ diff --git a/pandora/celery.py b/pandora/celery.py new file mode 100644 index 00000000..f53044cd --- /dev/null +++ b/pandora/celery.py @@ -0,0 +1,20 @@ +import os + +from celery import Celery + +root_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) +os.chdir(root_dir) + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') + +app = Celery('pandora') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks() diff --git a/pandora/settings.py b/pandora/settings.py index d654f948..72a48859 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -195,7 +195,7 @@ DATABASES = { } #rabbitmq connection settings -CELERY_RESULT_BACKEND = 'database' +CELERY_RESULT_BACKEND = 'django-db' CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT = ['json'] @@ -297,3 +297,8 @@ ALLOWED_HOSTS = ['*'] SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') DATA_UPLOAD_MAX_MEMORY_SIZE = 32 * 1024 * 1024 +try: + CELERY_BROKER_URL +except NameError: + CELERY_BROKER_URL = BROKER_URL +