0

Is the following if-else structure too non-deterministic for an Azure Durable Functions orchestration?:

[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;
}

Will hasExhaustedPartitions not work well with replay? When yes, what must done instead?

rasx
  • 5,288
  • 2
  • 45
  • 60

1 Answers1

1

There is nothing wrong with if/else when the evaluated condition is deterministic. In your case, the FUNC_NAME_ORCH_FUNC0 function will execute once, the result will be recorded in the history, and the recorded result will be used to initialize the hasExhaustedPartitions variable on all subsequent replays, so the condition is deterministic.

Anatoli Beliaev
  • 1,614
  • 11
  • 13