從我所知道的,有兩個文件描述瞭如何設置芹菜。有「Running the worker as a daemon」,有「First steps with Django」。如何用Django配置芹菜守護進程
Django文檔,它說:
我們還添加了Django的設置模塊爲芹菜配置源。這意味着您不必使用多個配置文件,而是直接從Django設置配置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由芹菜提供。/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
開始芹菜,這是行不通的。相反,很明顯,它並沒有從我的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_USER。問題是那些設置沒有被拾起。 – mlissner