小编典典

从主机运行主管,从virtualenv运行celery(Django应用)

redis

我正在尝试使用celery和redis队列来为我的Django应用执行任务。Supervisord通过安装在主机上apt- get,而celery驻留在我系统上的特定虚拟环境中,通过`pip安装。

结果,我似乎无法celery通过supervisor运行命令。如果我从virtualenv内部运行它,则在外部运行良好,但不能正常运行。如何使其在当前设置下运行?解决方案是否只是celery通过apt-
get而不是在virtualenv内部安装?请指教。

我在/etc/supervisor/conf.d中的celery.conf是:

[program:celery]
command=/home/mhb11/.virtualenvs/myenv/local/lib/python2.7/site-packages/celery/bin/celery -A /etc/supervisor/conf.d/celery.conf -l info
directory = /home/mhb11/somefolder/myproject
environment=PATH="/home/mhb11/.virtualenvs/myenv/bin",VIRTUAL_ENV="/home/mhb11/.virtualenvs/myenv",PYTHONPATH="/home/mhb11/.virtualenvs/myenv/lib/python2.7:/home/mhb11/.virtualenvs/myenv/lib/python2.7/site-packages"
user=mhb11
numprocs=1
stdout_logfile = /etc/supervisor/logs/celery-worker.log
stderr_logfile = /etc/supervisor/logs/celery-worker.log
autostart = true
autorestart = true
startsecs=10

stopwaitsecs = 600

killasgroup = true

priority = 998

我的Django项目的文件夹结构为:

/home/mhb11/somefolder/myproject
├── myproject
│   ├── celery.py       # The Celery app file
│   ├── __init__.py     # The project module file (modified)
│   ├── settings.py     # Including Celery settings
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── celerybeat-schedule
└── myapp
    ├── __init__.py
    ├── models.py
    ├── tasks.py        # File containing tasks for this app
    ├── tests.py
    └── views.py

如果我status通过supervisorctl 进行检查,则command在尝试在celery.conf中运行时出现致命错误。救命!

ps请注意,mhb11如果有必要,用户没有root特权。而且,/etc/supervisor/logs/celery- worker.log是空的。而且里面supervisord.log相关的错误我看到的是INFO spawnerr: can't find command '/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site- packages/celery/bin/‌​celery'


阅读 320

收藏
2020-06-20

共1个答案

小编典典

Celery二进制文件的路径是myenv/bin/celery您正在使用myenv/local/lib/python2.7/site- packages/celery/bin/cel‌‌​​ery

因此,如果您在终端上尝试传递给主管的命令(command = xxx),则应该得到相同的错误。

您需要将command=xxxcelery.conf中的替换为

command=/home/mhb11/.virtualenvs/myenv/bin/celery -A myproject.celery -l info

请注意,我还-A用celery应用程序代替了参数,而不是超级用户配置。这Celery应用相关项目目录集celery.conf

directory = /home/mhb11/somefolder/myproject

附带说明一下 ,如果您将Celery与Django一起使用,则可以使用Django的celery管理celery
manage.py,无需直接调用celery。喜欢

python manage.py celery worker
python manage.py celery beat

有关详细信息,请在此处阅读Django Celery的介绍。

2020-06-20