让Celery广播所有员工的返回结果 [英] Have Celery broadcast return results from all workers

查看:80
本文介绍了让Celery广播所有员工的返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从芹菜广播任务中的每个工作人员那里获得所有结果?我想监视所有工人是否一切正常.发送任务的工作人员清单也将不胜感激.

Is there a way to get all the results from every worker on a Celery Broadcast task? I would like to monitor if everything went ok on all the workers. A list of workers that the task was send to would also be appreciated.

推荐答案

否,这不容易实现.

但是您不必局限于内置的amqp结果后端,您可以使用Kombu( http://kombu.readthedocs.org )发送您自己的结果,这是Celery使用的消息传递库:

But you don't have to limit yourself to the built-in amqp result backend, you can send your own results using Kombu (http://kombu.readthedocs.org), which is the messaging library used by Celery:

from celery import Celery
from kombu import Exchange

results_exchange = Exchange('myres', type='fanout')

app = Celery()

@app.task(ignore_result=True)
def something():
    res = do_something()
    with app.producer_or_acquire(block=True) as producer:
        producer.send(
            {'result': res},
            exchange=results_exchange,
            serializer='json',
            declare=[results_exchange],
        )

producer_or_acquire 将使用芹菜创建一个新的 kombu.Producer 代理连接池.

producer_or_acquire will create a new kombu.Producer using the celery broker connection pool.

这篇关于让Celery广播所有员工的返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆