【问题标题】:Azure Durable Functions: am i using `!orchestrationContext.IsReplaying` correctly?Azure Durable Functions:我是否正确使用了 `!orchestrationContext.IsReplaying`?
【发布时间】: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


【解决方案1】:

我认为如果没有IsReplaying,您的代码应该可以正常工作。 CallActivityAsync() 方法将被多次调用,但对于给定的输入,它只会执行一次活动函数。在第一次执行之后,结果会在表存储中设置检查点,并且对该活动的连续调用将从表中返回结果,并且不会再次执行活动函数。

有关检查点和重放的更多信息:https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-orchestrations#reliability

我建议您将 FUNC1 的日志记录语句移入 FUNC1 活动函数。这样,您只记录实际的活动函数执行,而不是记录调用 CallActivityAsync 方法的次数。

【讨论】:

  • 在 AzFunc Core Tools 中我可以看到日志记录 inside FUNC1 在重放时一次又一次地运行(当if 门被移除时)
  • 这听起来很奇怪,不应该发生。你有我可以查看的示例回购吗?
  • 我没有公开的回购,但我有一个要点:gist.github.com/BryanWilhite/184501cfaa35cfd0a596535a4179c69f
猜你喜欢
  • 2022-10-23
  • 2022-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
  • 2014-07-19
相关资源
最近更新 更多