运行 来自主机的 supervisord,来自 virtualenv 的 celery(Django 应用程序)
Running supervisord from the host, celery from a virtualenv (Django app)
我正在尝试使用 celery 和 redis 队列为我的 Django 应用程序执行任务。 Supervisord 通过 apt-get
安装在主机上,而 celery 驻留在我系统上的特定 virtualenv 中,通过 pip 安装。
因此,我似乎无法通过 supervisord 将 celery
命令发送到 运行。如果我 运行 它来自 virtualenv 内部,它工作正常,在它之外,它没有。在我当前的设置下如何将其设置为 运行?解决方案是简单地通过 apt-get 安装 celery
,而不是在 virtualenv 中安装吗?请指教
我的celery.conf里面的/etc/supervisor/conf.d是:
[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
如果我通过 supervisorctl 进行 status
检查,我会在 command
上收到致命错误,我正试图在 celery.conf 中 运行。求助!
p.s。请注意,用户 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'
.
celery 二进制文件的路径是 myenv/bin/celery
而您使用的是 myenv/local/lib/python2.7/site-packages/celery/bin/celery
.
因此,如果您在终端上尝试传递给主管的命令 (command=xxx),您应该会得到同样的错误。
您需要将 celery.conf 中的 command=xxx
替换为
command=/home/mhb11/.virtualenvs/myenv/bin/celery -A myproject.celery -l info
请注意,我还用 celery app 替换了 -A
参数,而不是主管配置。此芹菜应用程序与您在 celery.conf
和
中设置的项目目录相关
directory = /home/mhb11/somefolder/myproject
附带说明,如果您将 Celery 与 Django 一起使用,则可以使用 Django 的 manage.py
管理 celery,无需直接调用 celery。喜欢
python manage.py celery worker
python manage.py celery beat
有关详细信息,请阅读 Django Celery 的介绍 here。
我正在尝试使用 celery 和 redis 队列为我的 Django 应用程序执行任务。 Supervisord 通过 apt-get
安装在主机上,而 celery 驻留在我系统上的特定 virtualenv 中,通过 pip 安装。
因此,我似乎无法通过 supervisord 将 celery
命令发送到 运行。如果我 运行 它来自 virtualenv 内部,它工作正常,在它之外,它没有。在我当前的设置下如何将其设置为 运行?解决方案是简单地通过 apt-get 安装 celery
,而不是在 virtualenv 中安装吗?请指教
我的celery.conf里面的/etc/supervisor/conf.d是:
[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
如果我通过 supervisorctl 进行 status
检查,我会在 command
上收到致命错误,我正试图在 celery.conf 中 运行。求助!
p.s。请注意,用户 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'
.
celery 二进制文件的路径是 myenv/bin/celery
而您使用的是 myenv/local/lib/python2.7/site-packages/celery/bin/celery
.
因此,如果您在终端上尝试传递给主管的命令 (command=xxx),您应该会得到同样的错误。
您需要将 celery.conf 中的 command=xxx
替换为
command=/home/mhb11/.virtualenvs/myenv/bin/celery -A myproject.celery -l info
请注意,我还用 celery app 替换了 -A
参数,而不是主管配置。此芹菜应用程序与您在 celery.conf
和
directory = /home/mhb11/somefolder/myproject
附带说明,如果您将 Celery 与 Django 一起使用,则可以使用 Django 的 manage.py
管理 celery,无需直接调用 celery。喜欢
python manage.py celery worker
python manage.py celery beat
有关详细信息,请阅读 Django Celery 的介绍 here。