Azure Durable Functions PowerShell - 奇怪的协调器行为

问题描述 投票:0回答:1

我目前面临着基于 powershell 的 azure 持久功能的奇怪行为。我尝试对其进行调试,并在 Microsoft 文档/Internet 上搜索类似案例。但对于协调者的行为,我的脑海中仍然留下一个问号。

编排器正在以一种奇怪且意想不到的方式执行我的持久活动功能,并一遍又一遍地重新运行。

让我快速向您介绍我的代码并在这里展示我的问题:

编曲:

param($Context)
$ErrorActionPreference = "Stop"
$output = @()

try {
    #Validate Input
    Write-Information "Orchestrator: Validating Input"
    $JSONString = ($Context.Input).ToString()
    if (-not ([string]::IsNullOrEmpty($JSONString))) {
        $InputPSObject = ConvertFrom-Json $JSONString

        try {
            $TestFunction = Invoke-DurableActivity -FunctionName ‘TestFunction’ -Input $InputPSObject
        }
        catch {
            Write-Warning "Orchestrator: Test Function: $($_.Exception.Message)"
        } 

    } else {
        Write-Error "Orchestrator: Could not validate Input. String is null or empty"
        throw
    }
} catch {
    Write-Error "Orchestrator: Could not validate Input. Unexpected error"
    Write-Warning "Orchestrator: $($_.Exception.Message)"
    throw
}

测试耐用功能

param($InputObject)
Write-Information: “TestFunction”
$ErrorActionPreference = "Continue"

if ($test) {

  $array = @()
try {
  ..do someting..
  if ($Object -eq "Test") {
    $array += $Object
  } else {
    Write-Warning "Object is empty"
  }
  return $array
}
catch {
  Write-Warning "Unexpected error"
}
}

仅供参考:该函数或多或少是我真实函数的一个示例,所以不要在这里感到困惑。但它应该有足够的代码来向您介绍这个问题。

执行日志流截图:

INFORMATION: Orchestrator: Validating Input
INFORMATION: TestFunction
WARNING: Object is empty
INFORMATION: Orchestrator: Validating Input
WARNING: Orchestrator: Test Function: Value cannot be null. (Parameter 'input').
Executed 'Functions.TestOrchestrator (Succeeded, Id=***, Duration=95ms)

行为/说明: 这些函数由 HTTP 触发器触发(JSON 文件在 http 正文中传输),并且协调器执行持久函数(如预期)

INFORMATION: Orchestrator: Validating Input
INFORMATION: TestFunction

然后在持久的“测试功能”中发生“错误”。但是没问题,错误被捕获(如预期),仅在日志流中显示一条警告消息:

WARNING: Object is empty

到目前为止,这仍然是预期的行为,一个空数组被返回到协调器(因为由于错误而无法填充任何值)。 但是接下来就变得令人困惑了: Orchestrator又从头开始运行,这可以通过日志流看到:

INFORMATION: Orchestrator: Validating Input

并再次跳转到try-catch函数的try块中,尝试重新执行测试持久函数(可以通过vscode中的调试来验证。)仅供参考:orchestrator中没有重试选项! 但是函数的第二次执行直接失败并且进入了catch块。我不知道为什么他认为函数的“输入”现在是空的?这也可以在日志流中看到:

WARNING: Orchestrator: Test Function: Value cannot be null. (Parameter 'input').

在我的高效 Azure 函数中,我有多个活动函数,他将为每个其他执行的函数重复该行为。因此,在执行完其他每个函数之后,他将尝试再次执行“TestFunction”,并再次失败并显示以下日志流消息:

INFORMATION: Orchestrator: Validating Input
WARNING: Orchestrator: Test Function: Value cannot be null. (Parameter 'input').

这似乎是一种非常奇怪的行为,但也许这是协调器的“正常”预期行为,我不知道。 如果有人可以向我解释这一点,我会很高兴,这样我就能更好地处理这种行为:)

非常感谢

编辑: HTTP 触发器代码,根据 @Ikhtesam Afrin 的要求:

HTTP 触发器

using namespace System.Net

param($Request, $TriggerMetadata)

$FunctionName = $Request.Params.FunctionName
$Body = $Request.Body
$InstanceId = Start-DurableOrchestration -FunctionName $FunctionName -InputObject $Body
Write-Host "Started orchestration with ID = '$InstanceId'"

$Response = New-DurableOrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
Push-OutputBinding -Name Response -Value $Response
azure powershell azure-functions azure-durable-functions
1个回答
0
投票

这似乎是一种非常奇怪的行为,但也许这是协调器的“正常”预期行为,我不知道。

是的,这是 orchestrator 函数的预期行为。

  • 请参阅此 MS Doc,其中内容如下。

enter image description here

  • 即使我可以看到,Orchestrator函数执行了两次。

enter image description here

  • 如果您要打开第一次运行,您将看到状态:已计划,运行时状态:待定

enter image description here

  • 同时,如果您检查活动函数完成时间,您将看到它在第一次运行Orchestrator函数后已完成。

enter image description here

  • 因此,在活动函数完成后再次执行Orchestrator函数,以更新历史表中的状态,即状态:已完成,运行时状态:已完成

enter image description here

  • Orchestrator
    函数将执行,直到state更新为completed
© www.soinside.com 2019 - 2024. All rights reserved.