celery - chaining groups and subtasks. -> out of order execution

前端 未结 2 622
醉话见心
醉话见心 2020-12-08 15:11

When I have something like the following

group1 = group(task1.si(), task1.si(), task1.si())
group2 = group(task2.si(), task2.si(), task2.si())

workflow = ch         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 15:41

    I have the same issue with celery, trying to have a workflow where the first step is "spawn a million tasks". Tried groups of groups, subtasks, eventually my step2 kicks off before step1 is over.

    Long story short I might have found a solution with the use of chords and a dumb finisher:

    @celery.task
    def chordfinisher( *args, **kwargs ):
      return "OK"
    

    Doing nothing much, but it enables me to do this:

    tasks = []
    for id in ids:
        tasks.append( mytask.si( id ) )
    step1 = chord( group( tasks ), chordfinisher.si() )
    
    step2 = ...
    
    workflow = chain( step1, step2 )
    

    Originally I wanted to have step1 in a subtask but for the same reason as suspected, the action of calling a group ends, the task is considered finished, and my workflow moves on...

    If someone has something better, I'm interested!

提交回复
热议问题