gpt4 book ai didi

c# - Azure Durable Functions 的 CallActivityWithRetryAsync 不会在失败时重试

转载 作者:行者123 更新时间:2023-12-03 01:20:26 24 4
gpt4 key购买 nike

在我的协调器功能中,我将请求文件上传到外部服务器。经过一段不确定的时间后,应该会生成一个响应文件。我需要轮询该文件并下载它。

我目前的做法是上传后等待10分钟。然后将内置的 CallActivityWithRetryAsync 与 RetryOptions 结合使用。第一次轮询/下载失败后,等待 5 分钟,然后再开始总共 10 次重试。仅当事件函数中抛出带有消息 RESPONSE_FILE_NOT_YET_AVAILABLE 的异常时,才应尝试重试。

        var nowIn10Minutes = ctx.CurrentUtcDateTime.AddMinutes(10);
await ctx.CreateTimer(nowIn10Minutes, CancellationToken.None);

const string RETRY_ERROR_MESSAGE = "RESPONSE_FILE_NOT_YET_AVAILABLE";
var retryOptions = new RetryOptions(TimeSpan.FromMinutes(5), 10)
{
Handle = ex => ex.Message == RETRY_ERROR_MESSAGE
};
await ctx.CallActivityWithRetryAsync(nameof(PollForResponseAndDownload), retryOptions, input);

但是,根据日志,此重试逻辑并未得到遵守。见下文。

在计时器中设置的等待 10 分钟后,编排立即失败并出现 FunctionFailedException。尽管日志中显示了正确的异常消息,但不会执行重试。

我是否从根本上误解了这个过程?以下是相关日志:

->上传请求后,等待10分钟

2022-01-31 00:00:06.740 <GUID>: Function 'MyOrchestrator (Orchestrator)' is waiting for input. Reason: CreateTimer:2022-01-31T00:10:06.5093237Z. IsReplay: False. State: Listening. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 112.
2022-01-31 00:00:06.741 <GUID>: Function 'MyOrchestrator (Orchestrator)' awaited. IsReplay: False. State: Awaited. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 113.

-> 10分钟后恢复,安排事件函数执行

2022-01-31 00:10:32.700 <GUID>: Function 'MyOrchestrator (Orchestrator)' was resumed by a timer scheduled for '2022-01-31T00:10:06.5093237Z'. IsReplay: False. State: TimerExpired. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 114.
2022-01-31 00:10:32.701 <GUID>: Function 'PollForResponseAndDownload (Activity)' scheduled. Reason: MyOrchestrator. IsReplay: False. State: Scheduled. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 115.
2022-01-31 00:10:32.701 <GUID>: Function 'MyOrchestrator (Orchestrator)' awaited. IsReplay: False. State: Awaited. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 116.

-> 启动事件功能。它立即失败并显示预期的 ex.Message,但仍然无法运行重试逻辑。

2022-01-31 00:10:32.715 <GUID>: Function 'PollForResponseAndDownload (Activity)' started. IsReplay: False. Input: (368 bytes). State: Started. HubName: <HUB-NAME>. AppName: <APP-NAME>. SlotName: Production. ExtensionVersion: 2.6.0. SequenceNumber: 117. TaskEventId: 5
2022-01-31 00:10:37.078 <GUID>: Function 'PollForResponseAndDownload (Activity)' failed with an error. Reason: System.Exception: RESPONSE_FILE_NOT_YET_AVAILABLE at MyNamespace.func._getResponseFileContents(String fileHeader) in C:\Users\me\source\AppName\func.cs:line ...
2022-01-31 00:10:37.364 <GUID>: Function 'MyOrchestrator (Orchestrator)' failed with an error. Reason: Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionFailedException: The activity function 'PollForResponseAndDownload' failed: "RESPONSE_FILE_NOT_YET_AVAILABLE". See the function execution logs for additional details. ---> System.Exception: RESPONSE_FILE_NOT_YET_AVAILABLE at ...

最佳答案

事件函数将“事件函数‘SomeActivityFunc’失败:”添加到消息中。因此,要么创建要引发的自定义异常类型并检查类型,请使用 .Contains 或检查“事件函数‘SomeActivityFunc’失败:RESPONSE_FILE_NOT_YET_AVAILABLE”。

Handle = ex => ex.Message == "Activity function 'SomeActivityFunc' failed: " + RETRY_ERROR_MESSAGE
Handle = ex => ex.Message.Contains(RETRY_ERROR_MESSAGE)
Handle = ex => ex is SomeCustomExceptionType

关于c# - Azure Durable Functions 的 CallActivityWithRetryAsync 不会在失败时重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70923345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com