芹菜后端启用,结果说不然

时间:2015-04-09 00:53:10

标签: python rabbitmq celery backend amqp

我会简短地说清楚:

项目目录

proj/__init__.py
    /tasks.py
    /celery_app.py

celery_app.py

from __future__ import absolute_import
from celery import Celery

app = Celery('proj',
         broker='amqp://',
         backend='amqp://',
         include=['proj.tasks'])

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
)

if __name__ == '__main__':
    app.start()

tasks.py

from __future__ import absolute_import
from celery import current_app
from celery.contrib.methods import task_method

class A:

    @current_app.task(filter=task_method)
    def add(self,x, y):
        return x + y

工作日志

 -------------- celery@mycomp.localdomain v3.1.17 (Cipater)
---- **** -----
--- * ***  * -- Linux-2.6.32-504.8.1.el6.x86_64-x86_64-with-centos-6.6-Final
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app:         proj:0x1dc12d0
- ** ---------- .> transport:   amqp://guest:**@localhost:5672//
- ** ---------- .> results:     amqp://
- *** --- * --- .> concurrency: 24 (prefork)
-- ******* ----
--- ***** ----- [queues]
 -------------- .> celery           exchange=celery(direct) key=celery


[tasks]
  . proj.tasks.add

[2015-04-08 17:45:20,788: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2015-04-08 17:45:20,801: INFO/MainProcess] mingle: searching for neighbors
[2015-04-08 17:45:21,812: INFO/MainProcess] mingle: all alone
[2015-04-08 17:45:21,828: WARNING/MainProcess] celery@mycomp.localdomain ready.
[2015-04-08 17:50:25,610: INFO/MainProcess] Received task: proj.tasks.add[e0020f67-dbe7-4f6d-9547-a8ace36c2a2c]
[2015-04-08 17:50:25,635: INFO/MainProcess] Task proj.tasks.add[e0020f67-dbe7-4f6d-9547-a8ace36c2a2c] succeeded in 0.023062946042s: 4

python shell

>>> from proj.tasks import A
>>> a = A()
>>> s = a.add.delay(2,2)
>>> s
<AsyncResult: e0020f67-dbe7-4f6d-9547-a8ace36c2a2c>
>>> s.backend
<celery.backends.base.DisabledBackend object at 0x113fdd0>

如您所见,我启用了后端。我正在使用amqp。但是,当我尝试获得结果时,它说我没有启用后端。

1 个答案:

答案 0 :(得分:0)

通过在tasks.py中包含行from proj.celery_app import app,后端开始工作。

这似乎是一个错误,因为current_app应该包含该后端实例。

我在celery github上打开了一个问题。希望这也有助于遇到此问题的任何人。

Link to the github issue