Pie*_*tro 1 python django celery django-celery
这种配置是正确的.我以错误的方式开始芹菜:(,没有指定项目名称.(芹菜工人-A hockey_manager -l info
我从1.6.5升级到Django 1.9,我不能再让芹菜配置工作了.
经过近两天寻找解决方案后,我没有找到任何工作.
芹菜没有检测到我的任务.我尝试过:
依赖
amqp==2.0.3
celery==3.1.23
Django==1.9.8
django-celery==3.1.17
kombu==3.0.35
Run Code Online (Sandbox Code Playgroud)
项目结构
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
Run Code Online (Sandbox Code Playgroud)
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))
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)
曲棍球/ tasks.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):
...
Run Code Online (Sandbox Code Playgroud)
来自芹菜的错误
[2016-07-23 17:05:46,231:ERROR/MainProcess]收到类型为'hockey.tasks.league_schedule_results'的未注册任务.该消息已被忽略并被丢弃.
我还从版本2.0开始从amqp收到弃用警告:
AMQPDeprecationWarning:在建立连接之前访问了连接上的.transport属性.现在支持此功能,但将在amqp 2.2.0中弃用.
Run Code Online (Sandbox Code Playgroud)Since amqp 2.0 you have to explicitly call Connection.connect() before using the connection. W_FORCE_CONNECT.format(attr=attr)))