Question

I want to pass the result of one task to another task. I am using chain

som = chain (task_async_get_me_friends.s((userId), parse_friends.s()))()
q = som.get()
print q

My intention is to create 2 task. First task get the friends of the user and then pass this friends in the JSON object to the parse_friends task. I am getting the result from task_async_get_me_friends but then cannot get parse_friends to be called

@celery.task
def task_async_get_me_friends(userId, *args):
   logger.info('First do something')
   users_friends = fb_get_friends(userId)
   # Till here everything is all good, I did see the celery logger. Getting result from fb
   return {'result':'success', 'data':users_friends}

@celery.task
def parse_friends(users_friends,*args,**kwargs):
   # This log line i cannot see in the celery
   logger.info('Second do something'+str(users_friends))
   # Do something with users_friends
Was it helpful?

Solution

EDIT: realized I had misunderstood which function did which

I'm still getting up to speed on celery, but I don't think your chain is doing what you want. Specifically chain takes a list of tasks; you're only providing 1 task (which happens to be using a 2nd task). I think what you want is:

som = chain (task_async_get_me_friends.s(userId),parse_friends.s())

This should call parse_friends and when that result is returned, pass that to task_async_get_me_friends (which has the first argument passed in as userId but is "waiting" for chain to provide the second argument (the json result).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top