首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在持久编排中使用`if`-``else`‘结构是“总是”错误的吗?

在持久编排中使用`if`-``else`‘结构是“总是”错误的吗?
EN

Stack Overflow用户
提问于 2020-03-24 02:32:22
回答 1查看 135关注 0票数 0

以下if-else结构对于Azure持久函数编排来说是否太不确定?

代码语言:javascript
运行
复制
[FunctionName(FUNC_NAME_ORCH0)]
public static async Task<string> RunPlayerYouTubeOrchestration(
    [OrchestrationTrigger] DurableOrchestrationContext orchestrationContext,
    ILogger log)
{
    if (!orchestrationContext.IsReplaying)
        log?.LogInformation(GetInvocationMessage(orchestrationContext, FUNC_NAME_ORCH0));

    var hasExhaustedPartitions = await orchestrationContext
        .CallActivityAsync<bool>(FUNC_NAME_ORCH_FUNC0, null);

    if (!hasExhaustedPartitions)
    {
        var jsonBlobs = await orchestrationContext
            .CallActivityAsync<string[]>(FUNC_NAME_ORCH_FUNC1, null);

        var tasks = new Task[jsonBlobs.Length];
        for (int i = 0; i < jsonBlobs.Length; i++)
        {
            var json = jsonBlobs[i];
            tasks[i] = orchestrationContext.CallActivityAsync(FUNC_NAME_ORCH_FUNC2, json);
        }

        if (!orchestrationContext.IsReplaying)
            log?.LogInformation($"{FUNC_NAME_ORCH0}: fan-out starting...");

        await Task.WhenAll(tasks);
    }
    else
    {
        var orc1InstanceId = await orchestrationContext
             .CallSubOrchestratorAsync<string>(FUNC_NAME_ORCH1, null);
        if (!orchestrationContext.IsReplaying)
            log?.LogInformation($"{FUNC_NAME_ORCH1} completed with instance ID `{orc1InstanceId}`.");

        var orc2InstanceId = await orchestrationContext
            .CallSubOrchestratorAsync<string>(FUNC_NAME_ORCH2, null);
        if (!orchestrationContext.IsReplaying)
            log?.LogInformation($"{FUNC_NAME_ORCH2} completed with instance ID `{orc2InstanceId}`.");

        if (!orchestrationContext.IsReplaying)
            log?.LogInformation($"{FUNC_NAME_ORCH_FUNC3}: calling `{PlayerYouTubeIndicesActivity.ProcedureNameResetYouTubePartitionInfoAsync}`...");
        await orchestrationContext
            .CallActivityAsync(FUNC_NAME_ORCH_FUNC3,
                PlayerYouTubeIndicesActivity.GetInput(
                    PlayerYouTubeIndicesActivity.ProcedureNameResetYouTubePartitionInfoAsync));
    }

    return orchestrationContext.InstanceId;
}

hasExhaustedPartitions不能很好地与replay一起工作吗?如果是,那么必须做些什么呢?

EN

回答 1

Stack Overflow用户

发布于 2020-03-25 00:49:22

当计算的条件是确定性的时,if/else没有什么问题。在您的示例中,FUNC_NAME_ORCH_FUNC0函数将执行一次,结果将记录在历史中,并且记录的结果将用于在所有后续重放中初始化hasExhaustedPartitions变量,因此条件是确定性的。

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

https://stackoverflow.com/questions/60819603

复制
相关文章

相似问题

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