[英]Celery with multiple django sites
I have a one django backend for few customer's sites: 我有几个客户站点的django后端:
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: 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.
另外,我在单独的服务器上有一个Redis。
I need some celery background tasks with database access. 我需要一些具有数据库访问权限的芹菜后台任务。
How can I do that? 我怎样才能做到这一点?
UPDATE 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
|- celery.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. 在celery.py中,您可以通过设置
DJANGO_SETTINGS_MODULE
env变量从相应的设置对象配置celery应用程序,并使用该变量来加载相应的设置。
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. 然后在有监督的情况下,通过将起始行指定为
celery multi -A my_proj
并使用正确的DJANGO_SETTINGS_MODULE
env变量,为每个站点分配自己的芹菜。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.