【发布时间】:2015-12-31 05:02:40
【问题描述】:
我一直在尝试通过将结果持久化到队列中来将 Celery 任务结果路由到另一个进程,并且另一个进程可以从队列中选择结果。所以,已经将 Celery 配置为 CELERY_RESULT_BACKEND = 'rpc',但是 Python 函数返回的值仍然没有持久化到队列中。
不确定是否需要任何其他配置或代码更改。请帮忙。
下面是代码示例:
芹菜.py
from __future__ import absolute_import
from celery import Celery
app = Celery('proj',
broker='amqp://',
backend='rpc://',
include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_RESULT_BACKEND = 'rpc',
CELERY_RESULT_PERSISTENT = True,
CELERY_TASK_SERIALIZER = 'json',
CELERY_RESULT_SERIALIZER = 'json'
)
if __name__ == '__main__':
app.start()
tasks.py
from proj.celery import app
@app.task
def add(x, y):
return x + y
运行 Celery 为
celery worker --app=proj -l info --pool=eventlet -c 4
【问题讨论】:
-
您如何检查结果是否未持久化?
-
启动 Celery 后,在 rabbitmq 管理界面中验证 - 没有队列绑定到 celeryresults 通道。