我有不同的兔子隊列,每個專用於一種特殊的訂單處理:是否可以使用芹菜的畫布基元的自定義路線?
# tasks.py
@celery.task
def process_order_for_product_x(order_id):
pass # elided ...
@celery.task
def process_order_for_product_y(order_id):
pass # elided ...
# settings.py
CELERY_QUEUES = {
"black_hole": {
"binding_key": "black_hole",
"queue_arguments": {"x-ha-policy": "all"}
},
"product_x": {
"binding_key": "product_x",
"queue_arguments": {"x-ha-policy": "all"}
},
"product_y": {
"binding_key": "product_y",
"queue_arguments": {"x-ha-policy": "all"}
},
我們必須通過設置CELERY_DEFAULT_QUEUE = 'black_hole'
然後從不black_hole
消耗執行顯式路由的政策。
每項任務可以使用芹菜的畫布元,像這樣:
# tasks.py
@celery.task
def process_order_for_product_x(order_id):
# These can run in parallel
stage_1_group = group(do_something.si(order_id),
do_something_else.si(order_id))
# These can run in parallel
another_group = group(do_something_at_end.si(order_id),
do_something_else_at_end.si(order_id))
# These run in a linear sequence
process_task = chain(
stage_1_group,
do_something_dependent_on_stage_1.si(order_id),
another_group)
process_task.apply_async()
假如我想要的celery.group
,celery.chord
,celery.chord_unlock
,等帆布任務的特定用途通過隊列流入其相應的產品,而不是被困在black_hole
中,有沒有辦法用自定義任務名稱或自定義routing_key來調用每個特定的畫布任務?
由於我不會進入的原因,我寧願不發送所有celery.*
任務到一個全部爲celery_canvas
的隊列,這正是我在此期間所做的。