Search code examples
pythoncelery

How can I trigger tasks from another task in Python Celery?


# get a list of stuff
@celery.task
def getList():
    listOfStuff = getStuff()
    for thing in listOfStuff:
        processThing.apply_async(args=(thing))


# another attempt at list of stuff
@celery.task
def getList():
    listOfStuff = getStuff()
    for thing in listOfStuff:
        processThing.s((thing))

@celery.task
def processThing(thing):
    pass

So neither getList() implementation triggers the processThing tasks. I can't figure out why. I'm guessing there is a better way of accomplishing what I'm trying to accomplish but I can't figure out what that is.

How can I kick off tasks from another task?


Solution

  • celery.execute.send_task("task.fqn", args=[], kwargs={})
    

    This is command that worked to spawn my tasks.