I began using celery 3.1.9 today with Django. This newer version has a tighter integration with django that removes the need to using django-celery.
I use multiple settings files and I was wondering if there was an easy way to specify which settings file to use when initializing the celery worker
?
With djcelery it is quite simply since it uses the manage.py commands.
I naively tried to check if
settings.DEBUG
was true in the celery.py file, but of course that failed because the settings were not loaded yet!
THe next step is to dive into the django-celery source and emulate what they are doing, but before that, I was hoping someone had found an easy way of achieving this?
Thank you
When initializing the celery worker on the command line, just set the environment variable prior to the celery command.
DJANGO_SETTINGS_MODULE='proj.settings' celery -A proj worker -l info
A solution is to use environment variables.
In celery.py
Instead of
use
With
get_env_setting
defined as:You could put that in your
settings.base.py
e.g. .Then set the
DJANGO_SETTINGS_MODULE
environment variable for each environment. E.g. set it tomy_project.settings.production
in the production environment. This variable can by permanently set by adding the following line to ~/.bashrc: