python使用celery做异步任务时的常见的问题

我这里用的是celery redis的组合,rabbitmq有些重型。

启动的时候报错,查了下文档,问题确认是全局变量一个参数的问题。

解决办法

    293 
–> 294         meta = self._get_task_meta_for(task_id)
    295         if cache and meta.get(‘status’) == states.SUCCESS:
    296             self._cache[task_id] = meta

AttributeError: ‘DisabledBackend’ object has no attribute ‘_get_task_meta_for’

测试的代码:

The full contents of the message body was:
{‘utc’: True, ‘chord’: None, ‘args’: (0, 0), ‘retries’: 0, ‘expires’: None, ‘task’: ‘tasks.add’, ‘callbacks’: None, ‘errbacks’: None, ‘timelimit’: (None, None), ‘taskset’: None, ‘kwargs’: {}, ‘eta’: None, ‘id’: ’48c13a71-ecda-4ef8-98ce-f223a28c0b97′} (209b)
Traceback (most recent call last):
  File “/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py”, line 455, in on_task_received
    strategies[name](message, body,
KeyError: ‘tasks.add’
[2014-04-23 09:57:16,673: ERROR/MainProcess] Received unregistered task of type ‘tasks.add’.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{‘utc’: True, ‘chord’: None, ‘args’: (0, 0), ‘retries’: 0, ‘expires’: None, ‘task’: ‘tasks.add’, ‘callbacks’: None, ‘errbacks’: None, ‘timelimit’: (None, None), ‘taskset’: None, ‘kwargs’: {}, ‘eta’: None, ‘id’: ‘eb1b8772-ca7f-4966-8033-7b4db2a82aa6′} (209b)
Traceback (most recent call last):
  File “/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py”, line 455, in on_task_received
    strategies[name](message, body,
KeyError: ‘tasks.add’

解决的办法:

最好是用配置文件的方式:

注释下: 

文章的原文,blog.xiaorui.cc

4 Responses

  1. 那时的风儿 2016年6月23日 / 上午10:25

    谢谢。

  2. orangle 2014年7月16日 / 下午12:38

    代码高亮调调啊。。。貌似有些错位了

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">