'How can I mix chain task with group task in celery

my task.py file

from celery import Task
from random import randint


@shared_task
def create_nb():
    a = randint(1, 100)
    b = randint(1, 100)
    return {"a":a, "b":b}

@shared_task
def add(a,b):
    return a+b

@shared_task
def sub(a,b)
    return a-b

I want to execute the create_nb task first then pass the return kwargs {"a":a,"b";b} to add() and sub() to execute in parallel

  from celery import chain,group
  from mainapp.tasks import *

res = chain([create_nb.s() , group(add.s(),sub.s())])() 

how can I implement this ?enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source