我看到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
的“正确”时机,或者使用不确定的代码是一种黑客行为吗?
发布于 2019-12-20 17:53:15
我认为您的代码在没有IsReplaying
的情况下应该可以很好地工作。CallActivityAsync()
方法将被多次调用,但对于给定的输入,它只执行一次活动函数。在第一次执行之后,结果将在表存储中设置检查点,对该活动的连续调用将从表中返回结果,并且不会再次执行该活动函数。
有关检查点和重播的更多信息,请访问:https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-orchestrations#reliability
我建议您将FUNC1 的日志语句移到 FUNC1 activity函数中。这样,您只会记录实际的活动函数执行,而不会记录调用CallActivityAsync
方法的时间。
https://stackoverflow.com/questions/59422765
复制相似问题