I have a one django backend for few customer's sites:
my_proj
|- my_proj
|- __init__.py
|- settings.py
|- settings_development.py
|- settings_production_1.py
|- settings_production_2.py
|- settings_production_3.py
|- my_app_1
|- my_app_2
...
settings_production_1.py:
from settings import *
DEBUG = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'customer_1_db',
'USER': 'some_user',
'PASSWORD': 'some_passw',
'HOST': '127.0.0.1',
'PORT': '',
}
}
MEDIA_ROOT = 'media/customer_1'
Each site is a separate proccess managed by supervisord and uses separate database. Also I have a redis on a separate server.
I need some celery background tasks with database access.
How can I do that?
UPDATE
Ok, I can run multiple celery workers. I can do that from console
$ export DJANGO_SETTINGS_MODULE=my_proj.settings_production_2
$ /home/.../my_vitrual_env/bin/celery -A my_proj worker -l info
But I can't run it from supervisord
[program:celery2]
directory=/home/.../my_proj
command=/home/.../my_vitrual_env/bin/celery -A asl worker -l info
environment=DJANGO_SETTINGS_MODULE=my_proj.settings_production_2
...
You configure an app for your project . eg:
my_proj
| - my_proj
|- __init__.py
|- settings.py
|- settings_development.py
|- settings_production_1.py
|- settings_production_2.py
|- settings_production_3.py
etc.
In the celery.py you configure the celery app from the appropriate settings object by setting the DJANGO_SETTINGS_MODULE
env variable and use that to load the appropriate settings.
And then in supervisord, you give each site its own celery by specifying the start line as celery multi -A my_proj
and with the correct DJANGO_SETTINGS_MODULE
env variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.