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 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 -minute wait?
- Aawait Task.Delay(TimeSpan.FromMinutes(5));
- BDateTime nextCheck = DateTime.UtcNow.AddMinutes(5);
await context.CreateTimer(nextCheck, CancellationToken.None); - DateTime nextCheck = context.CurrentUtcDateTime.AddMinutes(5);
await context.CreateTimer(nextCheck, CancellationToken.None);Cevap - DSystem.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
Anahtar Kavram
Durable Functions orchestrator constraints and durable timers
Tahmini Süre:1m 30s