You are developing a shipment monitoring workflow using C# Azure Durable Functions. The workflow must poll an external shipping provider API every 5 minutes for up to 2 hours, or terminate early if the status becomes 'Delivered'.
You write the following orchestrator function code:
csharp
[FunctionName("MonitorShipmentOrchestrator")]
public static async Task Run(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
string shipmentId = context.GetInput<string>();
DateTime endTime = DateTime.UtcNow.AddHours(2);
while (DateTime.UtcNow < endTime)
{
string status = await context.CallActivityAsync<string>("GetShipmentStatus", shipmentId);
if (status == "Delivered")
{
await context.CallActivityAsync("FinalizeOrder", shipmentId);
return;
}
await Task.Delay(TimeSpan.FromMinutes(5));
}
}
Which set of changes must you apply to the code to ensure that the orchestrator remains deterministic and executes correctly without blocking orchestrator threads?
- Replace DateTime.UtcNow with context.CurrentUtcDateTime, and replace await Task.Delay(TimeSpan.FromMinutes(5)) with await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(5), CancellationToken.None).Answer
- BReplace DateTime.UtcNow with context.CurrentUtcDateTime, but retain await Task.Delay(TimeSpan.FromMinutes(5)) as the await keyword prevents thread blocking by yielding execution back to the host.
- CRetain DateTime.UtcNow because the Durable Functions framework handles standard system clock calls during execution, but replace await Task.Delay(TimeSpan.FromMinutes(5)) with await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(5), CancellationToken.None).
- DReplace DateTime.UtcNow with context.CurrentUtcDateTime, and replace await Task.Delay(TimeSpan.FromMinutes(5)) with Thread.Sleep(TimeSpan.FromMinutes(5)) to execute the loop block synchronously.