public static async Task WaitForCompletionOrCreateCheckStatusResponseAsync()

in src/Worker.Extensions.DurableTask/DurableTaskClientExtensions.cs [34:84]


    public static async Task<HttpResponseData> WaitForCompletionOrCreateCheckStatusResponseAsync(
        this DurableTaskClient client,
        HttpRequestData request,
        string instanceId,
        TimeSpan? retryInterval = null,
        bool returnInternalServerErrorOnFailure = false,
        bool getInputsAndOutputs = false,
        CancellationToken cancellation = default
    )
    {
        TimeSpan retryIntervalLocal = retryInterval ?? TimeSpan.FromSeconds(1);
        try
        {
            while (true)
            {
                var status = await client.GetInstanceAsync(instanceId, getInputsAndOutputs: getInputsAndOutputs);
                if (status != null)
                {
                    if (status.RuntimeStatus == OrchestrationRuntimeStatus.Completed ||
#pragma warning disable CS0618 // Type or member is obsolete
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Canceled ||
#pragma warning restore CS0618 // Type or member is obsolete
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Terminated ||
                        status.RuntimeStatus == OrchestrationRuntimeStatus.Failed)
                    {
                        var response = request.CreateResponse(
                            (status.RuntimeStatus == OrchestrationRuntimeStatus.Failed && returnInternalServerErrorOnFailure) ? HttpStatusCode.InternalServerError : HttpStatusCode.OK);
                        await response.WriteAsJsonAsync(new
                        {
                            Name = status.Name,
                            InstanceId = status.InstanceId,
                            CreatedAt = status.CreatedAt,
                            LastUpdatedAt = status.LastUpdatedAt,
                            RuntimeStatus = status.RuntimeStatus.ToString(), // Convert enum to string
                            SerializedInput = status.SerializedInput,
                            SerializedOutput = status.SerializedOutput,
                            SerializedCustomStatus = status.SerializedCustomStatus
                        }, statusCode: response.StatusCode);

                        return response;
                    }
                }
                await Task.Delay(retryIntervalLocal, cancellation);
            }
        }
        // If the task is canceled, call CreateCheckStatusResponseAsync to return a response containing instance management URLs.
        catch (OperationCanceledException)
        {
            return await CreateCheckStatusResponseAsync(client, request, instanceId);
        }
     }