Karun
Karun

Reputation: 621

Running celery group: where two tasks are run in parallel to get results to produce a third result

How do I set it so that the dependent tasks are run in parallel (instead of sequentially) to reduce the overall execution time

.

@celery.task(name='master_task')
def process_chain(symbol):

   # g = group(get_latest_close_price.s(symbol), option_chain.s(symbol))
   g = group(option_chain.s(symbol), get_latest_close_price.s(symbol))

   results = g()

   with result.allow_join_result():
       data = results.get()
       data = util_transform_option_chain(data[1], data[0])

   return({'result':data})

Upvotes: 0

Views: 1138

Answers (1)

2ps
2ps

Reputation: 15976

group will definitely run in parallel . . . if you have multiple workers or concurrency > 1. But, just as an FYI--you may want to combine a chord with group to handle the result the way that you want.

Upvotes: 1

Related Questions