首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Azure持久函数:我是否正确使用了`!orchestrationContext.IsReplaying`?

Azure持久函数:我是否正确使用了`!orchestrationContext.IsReplaying`?
EN

Stack Overflow用户
提问于 2019-12-20 17:26:52
回答 1查看 196关注 0票数 1

我看到in Microsoft's example of fan-out并不关心‘防御’重播

但在这里我绝对需要if (!orchestrationContext.IsReplaying)

代码语言:javascript
运行
复制
[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的“正确”时机,或者使用不确定的代码是一种黑客行为吗?

EN

回答 1

Stack Overflow用户

发布于 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方法的时间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59422765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档