You are developing a software release pipeline using Azure Durable Functions. The workflow is written in C# (.NET Isolated process) and must implement a gated approval step. The orchestrator must send an approval notification to a release manager, wait for up to 24 hours for a response via an external event, and then either proceed with the deployment or cancel it. If the manager responds before the timeout, the workflow must prevent the timer from running to completion to avoid unnecessary execution.
Move the steps required to implement this gated approval pattern within the orchestrator function into the correct execution sequence.
- 1Call the activity function to send the approval request notification to the manager.
- 2Create a CancellationTokenSource, start a durable timer task using the token, and start an external event listener task.
- 3Block execution by calling Task.WhenAny on both the durable timer and external event tasks.
- 4Cancel the durable timer using the CancellationTokenSource if the external event task resolved first.
- 5Determine the workflow outcome (approved, rejected, or timed out) and call the corresponding deployment or cleanup activity.
Cevap
The correct sequence begins with notifying the manager, setting up the timer and event tasks, waiting for either task to resolve, canceling the timer if the event is received first, and finally triggering the appropriate deployment or cleanup activity.
In a C# Durable Functions orchestrator implementing a human interaction pattern with a timeout, the orchestrator first calls an activity to send the notification. Next, it must define the timer (linked to a cancellation token) and the external event listener. It then blocks execution using Task.WhenAny to wait for whichever occurs first. If the event occurs first, it is critical to cancel the timer using the CancellationTokenSource to prevent it from executing at a later time. Finally, the orchestrator calls the corresponding activity based on the outcome.
Adım Adım Çözüm
Anahtar Kavram
Implementing the Human Interaction pattern with timeouts in Azure Durable Functions using CancellationTokenSource and Task.WhenAny.
Tahmini Süre:2m 30s