[英]Explanation of retry logic in Azure Durable Functions
我是 Azure Durable Functions 的新手,正在嘗試了解重試邏輯和錯誤處理。
我有一個非常簡單的編排 function,它以扇入扇出模式執行 100 個動作函數。 我的期望是,當操作 function 由於任何原因中斷時,它會根據重試選項進行重試。 在我的例子中,我期望在最后的編排行(Write-Information $results.count)中得到 100 的計數,但是對於由於隨機錯誤拋出而出錯的每個操作 function,似乎沒有重試結果總是小於 100。
為什么會這樣,為什么我會多次看到 orchestrator output $results.count?
編排
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
行動
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
好吧,如果你想在你的中添加重試,你可以在你的function.json
中配置重試策略。
在此重試策略中,您可以設置maxRetryCount
,它表示 function 在停止前重試的次數。
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"
}
}
在這里,由於我已將重試計數設置為 1,因此 function 將嘗試執行兩次。
請參閱此MsDOC重試政策。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.