据我所知,有两份文件描述了如何设置 celery。有“将工作人员作为守护进程运行”和“使用 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
具有celery 提供的默认 init.d 脚本。/etc/defaults/celery
几乎什么都没有。只是指向我的应用程序的指针:export DJANGO_SETTINGS_MODULE='cl.settings'
/my-proj/celery.py
具有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
具有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
然而,当我开始使用 celery 时sudo service celeryd start
,它不起作用。相反,很明显它没有从我的 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
有什么想法可以让吊索不起作用?我错过了什么重要的东西吗?