[Answer]-Celery chain tasks

1๐Ÿ‘

โœ…

If you look at your swarm_restart task, you are chaining group_restart tasks. Here, the first task in the chain will execute fine but the the second task will throw error.

TypeError: group_restart() takes exactly 1 argument (2 given)

Because, the result of first task is passed as an argument to it. The same happens with the next tasks in the chain also.

For example,

from celery import task, chain

@app.task
def t1():
    return 't1'

@app.task
def t2():
   return 't2'

wrong_chain = chain( t1.s(), t2.s() )

If you execute wrong_chain it throughs the similar error even though you are not passing any arguments to t2

So, you have to change your work flow depending what you have to do.

๐Ÿ‘คChillar Anand

Leave a comment