任务.py:
from celery import Celery
from django.http import HttpResponse
from anyjson import serialize
celery = Celery('tasks', broker='amqp://guest@localhost//')
#@celery.task
def add(request):
x = int(request.GET['x'])
y = int(request.GET['y'])
result = x+y
response = {'status': 'success', 'retval': result}
return HttpResponse(serialize(response), mimetype='application/json')
启动工人后,我尝试了http调度程序:
from celery.task.http import URL
res = URL('http://localhost/add').get_async(x=10, y=10)
res.state
'PENDING'
并出现错误,例如 [2013-04-03 06:39:54,791: ERROR/MainProcess] 收到 u'celery.task.http.HttpDispatchTask' 类型的未注册任务。该消息已被忽略并丢弃。
你记得导入包含这个任务的模块吗?或者,也许您正在使用相对进口?更多:http ://docs.celeryq.org/en/latest/userguide/tasks.html#names
邮件正文的完整内容是:
{u'utc': True, u'chord': None, u'args': [u'http://localhost/add', u'GET'], u'retries': 0, u'expires': None, u'task': u'celery.task.http.HttpDispatchTask', u'callbacks': None, u'errbacks': None, u'taskset': None, u'kwargs': {u'y': 10, u'x': 10}, u'eta': None, u'id': u'29f83cc9-ba5a-4008-9d2d-6f7bb24b0cfc'} (288b)
回溯(最近一次通话最后):
File "/usr/local/gdp/python2.7.2/lib/python2.7/site-packages/celery-3.0.13-py2.7.egg/celery/worker/consumer.py", line 435, in on_task_received
strategies[name](message, body, message.ack_log_error)
KeyError: u'celery.task.http.HttpDispatchTask'