task - Azure Durable Functions:我是否正确使用了`!orchestrationContext.IsReplaying`?
问题描述
我在微软的扇出示例中看到,无需担心“防御”重播
但我绝对需要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
,或者使用低于确定性的代码是一种黑客行为?
解决方案
我认为您的代码在没有IsReplaying
. 该CallActivityAsync()
方法将被多次调用,但对于给定的输入,它只会执行一次活动函数。在第一次执行之后,结果会在表存储中设置检查点,并且对该活动的连续调用将从表中返回结果,并且不会再次执行活动函数。
有关检查点和重放的更多信息:https ://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-orchesstrations#reliability
我建议您将 FUNC1 的日志记录语句移到FUNC1 活动函数中。这样,您只记录实际的活动函数执行,而不是记录该CallActivityAsync
方法被调用的次数。
推荐阅读
- c# - ASP.NET MVC 客户端证书验证
- mysql - 转换 mysql date_i18n 中的旧时间戳数据
- python - 填充 3D 数组并绘制值
- python - 通过在没有 for 循环的函数内部以随机行为重复函数 n 次来创建一个 numpy 数组
- java - 我的布局不适合多种屏幕尺寸,我不知道如何在约束中控制项目视图大小
- pandas - OrderedDict 包含 DataFrame 列表
- spss - 如何在SPSS中将邮政编码与城市名称匹配?
- python - ModuleNotFoundError:python 行为中没有名为“前端”的模块
- sql - 是否存在与 Postgresql 中的任何内容都不匹配的转义字符?
- node.js - (节点:11168)UnhandledPromiseRejectionWarning:ValidationError:列表验证失败