Durable Functions and child orchestration

Ron Pitts 20 Reputation points
2023-05-18T23:43:33.6633333+00:00

I'm wondering how this is typically solved without using a child orchestration.

I currently have two activity triggers within a single orchestration trigger. Now one of those activity triggers should only fire once it receives an external event.

Additionally I want to introduce another external event

e.g.

Start on Orchestration Trigger Secondary Action
Call_Activity 1
External Event A Call_Activity 2
External Event B

So basically the Orchestration Trigger will wait until Call_Activity_1, External Event A, External Event B have completed.

External Event A has a child activity called Call_Activity 2

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,626 Reputation points Microsoft Employee
    2023-05-22T16:33:40.69+00:00

    @Ron Pitts Since Durable Functions are code-based workflows, you have complete control over how the flow works as possible within code.

    In this case, depending on which parts of the orchestration you need to run parallel, you will skip awaiting. Here is the approach I think you are looking for

    • Call Activity 1 and await the call
    • Create two wait for external event calls for A and B
    • await the one for A and when complete, call Activity B and await that call
    • Finally, await for event B

    The code would look something like this

    [FunctionName(nameof(SampleOrchestration))]
    public async Task<List<string>> SampleOrchestration([OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();
    
        // Wait for Call_Activity_1 to complete
        var activity1Output = await context.CallActivityAsync<string>("Call_Activity_1", null);
    
        // Wait for External Event A to complete
        var externalEventA = context.WaitForExternalEvent<string>("ExternalEventA");
        var externalEventB = context.WaitForExternalEvent<string>("ExternalEventB");
    
        // Wait for External Event A
        await externalEventA;
    
        // Call Call_Activity_2
        var activity2Output = await context.CallActivityAsync<string>("Call_Activity_2", null);
    
        // Wait for External Event B
        await externalEventB;
    
        outputs.Add(activity1Output);
        outputs.Add(activity2Output);
    
        return outputs;
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.