I want to use Azure Durable Functions to orchestrate my functions. This is my code (auto-generated by VS Code when you create a Durable Function) :
[FunctionName("testorchestration")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext context)
{
var outputs = new List<string>();
// Replace "hello" with the name of your Durable Activity Function.
outputs.Add(await context.CallActivityAsync<string>("testorchestration_Hello", "Tokyo"));
outputs.Add(await context.CallActivityAsync<string>("testorchestration_Hello", "Seattle"));
outputs.Add(await context.CallActivityAsync<string>("testorchestration_Hello", "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
[FunctionName("testorchestration_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log)
{
log.LogInformation($"Saying hello to {name}.");
return $"Hello {name}!";
}
[FunctionName("testorchestration_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
[OrchestrationClient]DurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
string instanceId = await starter.StartNewAsync("testorchestration", null);
return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req,instanceId);
}
I add await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req,instanceId);
because I need to wait for completion , and this is my problem.
If I wait for completion, it takes about ~2 seconds and sometimes 20 secondes (test on localhost) and I want to understand why because each function takes ~50ms to execute.
Maybe because this method calls await starter.GetStatusAsync(instanceId) everytime until the task is completed ?