【发布时间】:2021-09-29 13:52:36
【问题描述】:
我有一个似乎总是处于运行状态的持久函数。即使它成功完成。
它似乎完成了,然后它出于某种原因将RunningStatus 更新回Running。
我的日志到此结束:
[2021-07-22T08:52:59.211Z] Executing 'SavingsOrchestrator' (Reason='(null)', Id=36d509f3-4655-4382-9b72-ccb6fc39f413)
[2021-07-22T08:52:59.230Z] Executed 'SavingsOrchestrator' (Succeeded, Id=36d509f3-4655-4382-9b72-ccb6fc39f413, Duration=51ms)
[2021-07-22T08:53:02.206Z] SaveCustomerSavings stored 34 records.
[2021-07-22T08:53:02.210Z] Orechestrator_SaveCustomerSavings: Function 'SavingsOrchestrator (Orchestrator)' awaited. IsReplay: False. State: Awaited. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.5.0. SequenceNumber: 24.
[2021-07-22T08:53:02.214Z] Orechestrator_SaveCustomerSavings: Function 'SavingsOrchestrator (Orchestrator)' completed. ContinuedAsNew: False. IsReplay: False. Output: (null). State: Completed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.5.0. SequenceNumber: 25. TaskEventId: -1
[2021-07-22T08:53:02.214Z] Orechestrator_SaveCustomerSavings: Orchestration 'SavingsOrchestrator' awaited and scheduled 0 durable operation(s).
[2021-07-22T08:53:02.254Z] Orechestrator_SaveCustomerSavings: Appended 3 new events to the history table in 35ms
[2021-07-22T08:53:02.290Z] Orechestrator_SaveCustomerSavings: Updated Instances table and set the runtime status to 'Running'
[2021-07-22T08:53:02.292Z] Orechestrator_SaveCustomerSavings: Deleting [TaskCompleted#3] message from testhubname-control-00
我在代码中的基本操作如下:
我开始我的Orchestrator(作为单身人士):
await client.StartNewAsync<Task>("SavingsOrchestrator", _instanceId, null);
我的 Orchestrator 功能基本上是这样的:
[FunctionName(nameof(SavingsOrchestrator))]
public async Task SavingsOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger)
{
var a1 = await context.CallActivityAsync<List<MyModel>>("Activity1", null);
if (a1?.Any() != true)
{
return;
}
// Run as 4 parallel tasks.
var batchSize = a1.Count / 4 + 1;
var tasks = new List<Task<int>>();
foreach (var batch in a1.Batch(batchSize))
{
tasks.Add(context.CallActivityAsync<int>("Activity2", batch));
}
await Task.WhenAll(tasks);
var total = tasks.Sum(x => x.Result);
logger.LogInformation($"Done: {total}");
}
为什么我的 Durable Function 在成功运行后仍处于运行状态?
更新
在我的代码中,我使用Task.WhenAll 进行“扇出”。当我删除该代码并在一行中简单地调用 Activity2 时,将所有项目而不是批次传递给它:
// Pass all items to the Activity function
var total = await context.CallActivityAsync<int>("Activity2", a1);
然后它将RunningStatus 更新为Completed。
使用Task.WhenAll 似乎有问题。但是我直接从Microsoft Documentation得到了这个想法
【问题讨论】:
-
协调器函数执行似乎将进入不确定状态。阅读它here 并因此它将进入无限运行状态。
标签: .net-core azure-functions azure-durable-functions