此配置爲正確。我開始芹菜 走錯路了:(,不指定項目名稱。(芹菜工人-A hockey_manager -l信息Django 1.9 +芹菜未註冊任務
我也從1.6.5升級到1.9的Django,我不能讓。芹菜配置工作再次
經過近兩天尋找一個解決方案,我也沒發現什麼工作的
芹菜沒有檢測到我的任務我試着用:
- 個CELERY_IMPORTS
- autodiscover_tasks
- 綁定=真
依賴
amqp==2.0.3
celery==3.1.23
Django==1.9.8
django-celery==3.1.17
kombu==3.0.35
項目結構
hockey_manager/__ init__.py
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
hockey_manager/celery.py
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', 'hockey_manager.settings.common')
app = Celery('hockey_manager')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
# load task modules from all registered Django app configs.
app.autodiscover_tasks(['hockey'])
# 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)
# Celery backend configs
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)
if __name__ == '__main__':
app.start()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
hockey_manager /設置/ common.py
INSTALLED_APPS = [
...
'hockey',
'djcelery',
'kombu.transport.django',
...
]
##
# Celery
##
# BROKER_POOL_LIMIT = 3
BROKER_URL = os.environ.get('CLOUDAMQP_URL')
#BROKER_URL = 'django://'
# List of modules to import when celery starts.
CELERY_IMPORTS = ('hockey.tasks',)
#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
曲棍球/任務.py
from __future__ import absolute_import
from hockey_manager.celery import app
@app.task(name='hockey.tasks.league_schedule_results')
def league_schedule_results(schedule, statistics):
...
從芹菜錯誤
[2016年7月23日17:05:46231:ERROR/MainProcess]所獲未註冊 任務類型 'hockey.tasks.league_schedule_results' 的。 該消息已被忽略並丟棄。
我也是從收到棄用警告AMQP從2.0版本開始:
AMQPDeprecationWarning:連接上的.transport屬性是 訪問建立連接之前 。目前支持此功能,但在amqp 2.2.0中會棄用 。
Since amqp 2.0 you have to explicitly call Connection.connect() before using the connection. W_FORCE_CONNECT.format(attr=attr)))
。它顯示在我的依賴列表中。版本3.1.17 – Pietro
我使用它與Django 1.9.1,我不需要celery.py文件進行配置。我剛剛給你建議嘗試鏈接中提到的步驟。可能會遵循這些步驟,您將使用django正確配置芹菜1.9.1 –
我會試一試,讓你知道。謝謝 – Pietro