How to route a chain of tasks to a specific queue in celery?

前端 未结 3 1114
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 07:21

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

task.apply_async(queue=\'beetroot\')

But if I create a chain:

chain = t         


        
3条回答
  •  被撕碎了的回忆
    2020-12-31 07:46

    Ok I got this one figured out.

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

    subtask definition:

    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()
    

    or,

    chain.delay()
    

    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.

提交回复
热议问题