Home > OS >  How to add Azure durableActivity to batch
How to add Azure durableActivity to batch

Time:09-29

    $batch = @(
        Invoke-DurableActivity -FunctionName "F_ComputeEngineTasks" -Input (ConvertTo-json $computeEngineTasksInput -Depth 3) -NoWait
        Invoke-DurableActivity -FunctionName "F_UpdateInstancesAndMembers" -Input (ConvertTo-Json $updateInstancesAndMembersInput) -NoWait
        foreach ($contactId in $members.contacts.modified.Keys) {
            $taskInput = @{contactId = $contactId; contactDetails = $members.contacts.modified.$contactId }
            Invoke-DurableActivity -FunctionName "F_UpdateContactInfo" -Input (ConvertTo-json $taskInput -Depth 3) -NoWait
        }    
    )
    
    $output = Wait-ActivityFunction -Task $batch 

I want to execute with parallelism F_ComputeEngineTasks, F_UpdateInstanceAndMembers and all F_UpdateContactInfo. I tried to make a batch and execute it ... thing is I have no idea if this is working or not (I get all the outputs of my functions but I have no way to know if they have been executed at the same time). If someone can tell me if I am doing wrong or not I gladdly appreciate.

CodePudding user response:

You code looks correct. Whether the activities actually run concurrently or not depends on many factors (scale out, concurrency limits, workload, etc.). Strictly speaking, using Invoke-DurableActivity with the -NoWait means that the function author does not object to running these activities concurrently, but it does not guarantee that they indeed will run concurrently. It is still up to the Azure Functions platform to determine the execution order depending on the available resources and concurrency configuration settings (such as https://aka.ms/functions-powershell-concurrency).

Perhaps the easiest way to check if your activities run in parallel or not is to measure the time it takes for finishing the entire orchestration and compare it with the expectations. You may need to insert artificial delays into your activities to measure confidently. But, if you cannot measure the difference, does the answer really matter to you? :-)

  • Related