We have a HttpTrigger
Azure function app and this is calling a durable function. This durable function is returning a HttpResponseData
after calling the CreateCheckStatusResponseAsync
.
We weren't able to create a custom response and getting the response from CreateCheckStatusResponseAsync
only.
Please advice how to customise this response.
This is the sample code:
// Function app
[Function("HelloCities_HttpStart")]
public static async Task<HttpResponseData> HttpStart([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("HelloCities_HttpStart");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(HelloCities));
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
The response that we are expecting should be like this:
But the response we are getting instead is:
We have a HttpTrigger
Azure function app and this is calling a durable function. This durable function is returning a HttpResponseData
after calling the CreateCheckStatusResponseAsync
.
We weren't able to create a custom response and getting the response from CreateCheckStatusResponseAsync
only.
Please advice how to customise this response.
This is the sample code:
// Function app
[Function("HelloCities_HttpStart")]
public static async Task<HttpResponseData> HttpStart([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("HelloCities_HttpStart");
// Function input comes from the request content.
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(HelloCities));
logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}
The response that we are expecting should be like this:
But the response we are getting instead is:
Share Improve this question edited 3 hours ago marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked 6 hours ago Anuraj RajagopalAnuraj Rajagopal 355 bronze badges1 Answer
Reset to default 0When you call await client.ScheduleNewOrchestrationInstanceAsync
it's only scheduling the Orchestration to start. That will take a finite amount of time.
Meanwhile, you immediately proceed to checking the Orchestration status, even though it probably hasn't had time to start yet.
There are a few solutions.
Not very elegant: add a
Task.Delay
of a few seconds after scheduling the Orchestration, to allow time for it to start. This is pretty bad, because there's no guarantee how long you need to wait so it will sometimes fail; and it will slow your HTTP request.Better: make your Function return a 202 Accepted response^1 with another URL (another Function) that they can call to check the status of the Orchestration, and move that code into there.