Parallelization in Durable Function

Viewed 625

I'm trying to understand how parallelization works in Durable Function. I have a durable function where I first get a list of items and then all items should run in parallel. Meaning the time taken to execute 10 items and 10000 items should be the same? How do I do that?

1 Answers

There are two approaches that are possible. The first is to use a suborchestrator for each job so that each suborchestrator handles just a specific job. Here is the docs for this approach https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-sub-orchestrations?tabs=csharp Example from docs seem to be alike to yours.

The other is to use ContinueWith so that each job has its own "chain"

List<Task> tasks = new List<Task>();
foreach (var job in jobs){
   tasks.Add(context.CallActivityAsync<Group>(nameof(GroupNameReaderFunction), job)
        .ContinueWith(prevTask => emailTasks.Add(context.CallActivityAsync(nameof(EmailSenderFunction), prevTask.Result))));
}
await Task.WhenAll(tasks);
Related