【发布时间】:2016-02-07 04:49:00
【问题描述】:
据我所知,有两个文档描述了如何设置 celery。有“Running the worker as a daemon”和“First steps with Django”。
在 Django 文档中,它说:
我们还添加了 Django 设置模块作为 Celery 的配置源。这意味着您不必使用多个配置文件,而是直接从 Django 设置中配置 Celery。
听起来很棒。但是,据我所知,这些是完整的 Celery 守护进程所需的文件:
/etc/init.d/celeryd/etc/defaults/celery/my-proj/celery.py/my-proj/__init__.py
还有可能:
/my-proj/settings.py
文件太多了。我想我已经把它们都设置好了:
-
/etc/init.d/celeryd有 the default init.d script 由 celery 提供。 -
/etc/defaults/celery几乎一无所有。只是指向我的应用程序的指针:export DJANGO_SETTINGS_MODULE='cl.settings' -
/my-proj/celery.py有来自First Steps with Django 的推荐文件:from __future__ import absolute_import import os from celery import Celery # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') from django.conf import settings # noqa app = Celery('proj') # Using a string here means the worker will not have to # pickle the object when using Windows. app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) -
/my-proj/__init__.py有来自First Steps with Django 的推荐代码:from __future__ import absolute_import # This will make sure the app is always imported when # Django starts so that shared_task will use this app. from .celery import app as celery_app
我的settings.py 文件中有所有与芹菜相关的设置,如下所示:
CELERY_BIN = '/var/www/.virtualenvs/my-env/bin/celery'
CELERYD_USER = 'www-data'
CELERYD_GROUP = 'www-data'
CELERYD_CONCURRENCY = 20
BROKER_URL = 'redis://'
BROKER_POOL_LIMIT = 30
然而,当我使用 sudo service celeryd start 启动 celery 时,它不起作用。相反,很明显它没有从我的 Django 项目中获取我的设置,因为它说:
Nov 05 20:51:59 pounamu celeryd[30190]: celery init v10.1.
Nov 05 20:51:59 pounamu celeryd[30190]: Using config script: /etc/default/celeryd
Nov 05 20:51:59 pounamu celeryd[30190]: No passwd entry for user 'celery'
Nov 05 20:51:59 pounamu su[30206]: No passwd entry for user 'celery'
Nov 05 20:51:59 pounamu su[30206]: FAILED su for celery by root
Nov 05 20:51:59 pounamu su[30206]: - ??? root:celery
Nov 05 20:51:59 pounamu systemd[1]: celeryd.service: control process exited, code=exited status=1
有什么想法可以解决吊索不工作的问题吗?我错过了什么重要的东西吗?
【问题讨论】:
-
您找到解决方案了吗?面临同样的问题
-
是的,我确定我成功了,但是不,我不记得缺少的拼图是什么。已经有好几个版本了,很多年了。
标签: django celery virtualenv django-celery celeryd