0

I'm new to Azure Durable Functions and am trying to understand the retry logic and error handling.

I have a very simple orchestration function that executes 100 action functions in a fan-in fan-out pattern. My expectation is that when an action function breaks for whatever reason it is retried based on the retry options. In my case I'm expecting that I get a count of 100 in the final orchestration line (Write-Information $results.count), but for every action function that errors out due to my random error throwing, it seems no retry is done and the results is always less than 100.

Why is this happening, also why am I seeing the orchestrator output $results.count multiple times?

Orchestration

param($Context)

$range = 1..100

$retryOptions = New-DurableRetryOptions -FirstRetryInterval (New-TimeSpan -Seconds 1) -MaxNumberOfAttempts 10

$tasks =
    foreach ($num in $range) {
        try{
            Invoke-DurableActivity -FunctionName 'RandomWaitActivity' -Input $num -NoWait -RetryOptions $retryOptions
        }
        catch{
            Write-Output $_.Exception.Message
        }
    }

$results = Wait-ActivityFunction -Task $tasks

Write-Information $results.count

Action

param($number)

Write-Output "Received $number"
$random = Get-Random -Minimum 1 -Maximum 20
if($random -eq 13){
    Throw "13 is a unlucky number"
}
Start-Sleep -Milliseconds $random
return $number
Mark Priem
  • 367
  • 2
  • 4
  • 16

1 Answers1

0
  • Well, If you want to add retry in your, you can configure retry policy in your function.json.

  • In this retry policy you can set maxRetryCount which represent the number of times a function will retry before stopping.

function.json :-

{
    "bindings": [
        {
    "authLevel": "anonymous",
    "type": "httpTrigger",
    "direction": "in",
    "name": "Request",
    "methods": [
            "get",
            "post"
        ]
    },
    {
    "type": "http",
    "direction": "out",
    "name": "Response"
    }   
    ],

"retry": {
    "strategy": "fixedDelay",
    "maxRetryCount": 1,
    "delayInterval": "00:00:10"
    }
}

Here Since I have set the retry count to 1 the function will try to execute twice.

enter image description here

Refer this MsDOC on retry policy.

Mohit Ganorkar
  • 1,917
  • 2
  • 6
  • 11
  • Thanks for your response, but that only helps with normal functions. I'm working with durable functions where actions are called by orchestrators. The retries should - according to the documentation - be handled by a retryoptions object, which is not working in my case. – Mark Priem Dec 04 '22 at 15:06