Soru

Zorluk: OrtaImplement Durable Functions

You are developing a serverless monitoring solution using Azure Durable Functions in C# (.NET Isolated). The orchestrator function is designed to poll an external database migration status endpoint every 55 minutes until the status returns as 'Success' or 'Failed'. To comply with orchestrator constraints and avoid wasting resources, the orchestrator must yield execution and release the thread between status checks.

Which code segment should you use in the orchestrator function to implement the 55-minute wait?

  1. A
    await Task.Delay(TimeSpan.FromMinutes(5));
  2. B
    DateTime nextCheck = DateTime.UtcNow.AddMinutes(5);
    await context.CreateTimer(nextCheck, CancellationToken.None);
  3. DateTime nextCheck = context.CurrentUtcDateTime.AddMinutes(5);
    await context.CreateTimer(nextCheck, CancellationToken.None);
    Cevap
  4. D
    System.Threading.Thread.Sleep(TimeSpan.FromMinutes(5));

Cevap

The correct code segment uses context.CurrentUtcDateTime and context.CreateTimer to create a deterministic, durable delay.
The correct code segment utilizes the context object's CurrentUtcDateTime property to calculate a deterministic expiration time, and then calls context.CreateTimer. This ensures that the time remains identical during orchestrator replays, preventing execution mismatches, while safely yielding thread resources back to the hosting platform.

Adım Adım Çözüm

1
Analyze the orchestrator function requirements for delaying execution.
The orchestrator must pause for 55 minutes in a durable, non-blocking, and deterministic manner.
Orchestrators are replayed to rebuild state, meaning standard thread-blocking or non-durable asynchronous delays are invalid.
2
Evaluate the source of current time inside the orchestrator.
Using DateTime.UtcNow is non-deterministic. Using context.CurrentUtcDateTime is deterministic.
DateTime.UtcNow changes on each replay execution, whereas context.CurrentUtcDateTime reads the execution history to return the same timestamp consistently.
3
Select the correct mechanism to register the timer with the Durable Functions framework.
Use context.CreateTimer with a deterministic target time.
context.CreateTimer writes a timer start event to the history and yields execution, allowing the system to scale to zero until the timer fires.

Anahtar Kavram

Durable Functions orchestrator constraints and durable timers
Tahmini Süre:1m 30s
Bu soruyu puanla