I do not like the fact that the Celery app config hardcodes a settings module. This makes it necessary to edit taskapp/celery.py after deployment, which is not ideal.

This moves the choice of a settings module to config/celery_config.py, where it belongs.
This commit is contained in:
Martin Diers 2015-07-15 11:48:48 -05:00
parent 696d1c5606
commit 324785ea77
2 changed files with 6 additions and 1 deletions

View File

@ -0,0 +1,4 @@
# This tells Celery which Django settings module it should use.
# This decouples the taskapp configuration from a specific instance of the project.
DJANGO_SETTINGS_MODULE = 'config.settings.local'

View File

@ -4,10 +4,11 @@ import os
from celery import Celery from celery import Celery
from django.apps import AppConfig from django.apps import AppConfig
from django.conf import settings from django.conf import settings
from config import celery_config
if not settings.configured: if not settings.configured:
# set the default Django settings module for the 'celery' program. # set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") os.environ.setdefault("DJANGO_SETTINGS_MODULE", celery_config.DJANGO_SETTINGS_MODULE)
app = Celery('{{cookiecutter.repo_name}}') app = Celery('{{cookiecutter.repo_name}}')