【发布时间】:2019-12-20 09:26:51
【问题描述】:
我看到in Microsoft's example of fan-out 表示无需担心“防御”重放
但我在这里绝对需要if (!orchestrationContext.IsReplaying):
[FunctionName(FUNC_NAME_ORCH)]
public static async Task<string> RunPlayerYouTubeOrchestration(
[OrchestrationTrigger] DurableOrchestrationContext orchestrationContext,
ILogger log)
{
log?.LogInformation($"{FUNC_NAME_ORCH}: {nameof(RunPlayerYouTubeOrchestration)} invoked...");
log?.LogInformation($"{FUNC_NAME_ORCH}: {nameof(DurableOrchestrationContextBase.InstanceId)} {orchestrationContex
log?.LogInformation($"{FUNC_NAME_ORCH}: calling {FUNC_NAME_ORCH_FUNC0}.c ..");
var jsonBlobs = await orchestrationContext
.CallActivityAsync<IEnumerable<string>>(FUNC_NAME_ORCH_FUNC0, null);
if ((jsonBlobs == null) || !jsonBlobs.Any())
{
var errorMessage = $"{FUNC_NAME_ORCH}: The expected JSON blobs from `{FUNC_NAME_ORCH_FUNC0}` are not here.";
log?.LogError(errorMessage);
throw new NullReferenceException(errorMessage);
}
if (!orchestrationContext.IsReplaying)
{
var tasks = jsonBlobs.Select(json =>
{
log?.LogInformation($"{FUNC_NAME_ORCH}: calling {FUNC_NAME_ORCH_FUNC1}...");
return orchestrationContext.CallActivityAsync(FUNC_NAME_ORCH_FUNC1, json);
});
log?.LogInformation($"{FUNC_NAME_ORCH}: fan-out starting...");
await Task.WhenAll(tasks);
}
log?.LogInformation($"{FUNC_NAME_ORCH}: fan-out complete.");
log?.LogInformation($"{FUNC_NAME_ORCH}: calling {FUNC_NAME_ORCH_FUNC2}...");
await orchestrationContext.CallActivityAsync(FUNC_NAME_ORCH_FUNC2, null);
return orchestrationContext.InstanceId;
}
没有这个if门,FUNC_NAME_ORCH_FUNC1将被无限调用
我在这里做错了什么?是否有使用!orchestrationContext.IsReplaying 的“正确”时间,或者使用非确定性代码是一种黑客行为?
【问题讨论】:
-
我现在确信在 Azure Function Orchestration 中使用
await Task.WhenAll(tasks)是不是的方法(它可能是反模式);查看 Microsoft 最新的 Durable 函数示例,其中它们循环遍历一堆城市名称,并且函数等待每次调用 once;我上面的工作是试图让 AF 等待 几个 超出编排上下文的调用
标签: task azure-functions deterministic non-deterministic azure-durable-functions