2

I am trying to run a durable function with Fan-In/Fan-Out to handle several concurrent calls. At the moment I get the output of all the calls at the end. However, I wanted to know if there was any way I could get the output of whichever calls have finished and return it via Custom Status while waiting for the rest of the calls to process?

parallel_tasks = [ context.call_activity("Activity", url) for url in context.get_input()["URLs"] ]
outputs = yield context.task_all(parallel_tasks)
return outputs
HITman
  • 43
  • 5

1 Answers1

0

Instead of task_all, I believe you could call task_any which would return when any of the tasks complete.

You could then loop over tasks array to find the ones that completed, update the custom status, filter the array and call task_any on the remaining. Repeat until all the tasks are completed.

Don't have python code ready to share but here is pseudo code of a recursive function that should do the trick

func monitor_all(a /* array of tasks */) {
  if (a.length === 0) return

  yield context.task_any(a)

  a.forEach(t => t.is_completed && update_status(t))

  return yield monitor_all(a.filter(t => !t.is_completed)
}
PramodValavala
  • 6,026
  • 1
  • 11
  • 30
  • I'm curious if anyone has tried this and if it works? I need to accomplish something similar to the OP. – Emac Jun 26 '21 at 18:16