如何将任务链路由到芹菜中的特定队列? [英] How to route a chain of tasks to a specific queue in celery?

查看:140
本文介绍了如何将任务链路由到芹菜中的特定队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将任务路由到特定队列时,它可以正常工作:

When I route a task to a particular queue it works:

task.apply_async(queue='beetroot')

但是,如果我创建了一个链条:

But if I create a chain:

chain = task | task

然后我写

chain.apply_async(queue='beetroot')

忽略queue关键字并分配给默认的 celery队列。

It seems to ignore the queue keyword and assigns to the default 'celery' queue.

如果celery支持链式路由-所有任务都在同一队列中顺序执行,那就太好了。 / p>

It would be nice if celery supported routing in chains - all tasks executed sequentially in the same queue.

推荐答案

好,我已经弄清楚了。

将必需的执行选项(例如queue =或countdown =)添加到子任务定义中,或通过部分操作:

You have to add the required execution options like queue= or countdown= to the subtask definition, or through a partial:

子任务定义:

from celery import subtask

chain = subtask('task', queue = 'beetroot') | subtask('task', queue = 'beetroot')

partial:

chain = task.s().apply_async(queue = 'beetroot') | task.s().apply_async(queue = 'beetroot')

然后通过以下方式执行链:

Then you execute the chain through:

chain.apply_async()

chain.delay()

任务将被发送到甜菜根队列。最后一条命令中的额外执行参数不会执行任何操作。在Chain(或Group,或任何其他Canvas基元)级别应用所有这些执行参数,将是一种不错的选择。

And the tasks will be sent to the 'beetroot' queue. Extra execution arguments in this last command will not do anything. It would have been kind of nice to apply all of those execution arguments at the Chain (or Group, or any other Canvas primitives) level.

这篇关于如何将任务链路由到芹菜中的特定队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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