Question

Difficulty: MediumImplement Durable Functions

You are implementing an Azure Durable Functions workflow in C# to handle a human approval process with a 2424-hour escalation timeout. Order the steps in the sequence they occur during a successful execution where a manager approves the request within the 2424-hour window.

  1. 1The orchestrator function calls a notification activity function, creates a durable timer task using CreateTimer, and creates an event listener task using WaitForExternalEvent.
  2. 2The orchestrator function awaits Task.WhenAny on the timer task and the event listener task, which yields execution and saves the current orchestration state to Azure Storage.
  3. 3An external client function receives the user's action and calls RaiseEventAsync on the durable orchestration client to deliver the event payload to the orchestrator.
  4. 4The orchestrator function is awakened, replays its execution history to rebuild state, evaluates that the external event task has completed, and cancels the active timer task.
  5. 5The orchestrator function calls a final activity function to process the approval outcome and completes the orchestration.

Answer

The correct sequence of events is: the orchestrator sets up the timer and event listener tasks, yields execution using Task.WhenAny to persist state, receives the external event raised by the client function, wakes up to replay history and cancel the timer, and finally executes the activity to process the decision.
The correct sequence begins with the orchestrator defining the approval notification and wait tasks. Next, it yields control by awaiting Task.WhenAny, which saves state. A client function then raises the event using the orchestration client. The orchestrator wakes up, replays state to recognize the event completion, cancels the timer, and finally executes the final approval activity.

Step-by-Step Solution

1
Identify the initialization step of the Human Interaction pattern in the orchestrator.
The orchestrator initiates tasks for both the event listener (WaitForExternalEvent) and the escalation timer (CreateTimer).
Both tasks must be defined before the orchestrator can wait on them.
2
Identify how the orchestrator pauses execution while waiting for either event to complete.
The orchestrator awaits Task.WhenAny on the timer and event tasks, yielding control and saving state.
Awaiting Task.WhenAny prevents active blocking and ensures the current state is saved to storage.
3
Determine the mechanism by which the orchestrator is notified of user approval.
An external client function calls RaiseEventAsync with the decision.
Since the orchestrator is asleep, an external process must push the event to resume execution.
4
Analyze the behavior of the orchestrator upon receiving the event.
The orchestrator wakes up, replays its history to restore state, evaluates the completed event, and cancels the timer.
Replaying history ensures the orchestrator rebuilds state deterministically, and canceling the timer avoids unnecessary escalation.
5
Determine the final step in the workflow.
The orchestrator executes the activity to process the decision and completes.
The workflow logic is finished once the final processing activity completes.

Key Concept

Orchestrating human interaction patterns and managing state lifecycle in Azure Durable Functions
Estimated Time:1m 30s
Rate this question