microsoft / durabletask-dotnet

Out-of-process .NET SDK for the Durable Task Framework
MIT License
112 stars 33 forks source link

ScheduleNewOrchestrationInstanceAsync() is Not Scheduling an Orchestration #256

Open tomseida opened 9 months ago

tomseida commented 9 months ago

Using StartOrchestrationOptions.StartAt property when calling ScheduleNewOrchestrationInstanceAsync() does not schedule an orchestration. Orchestrations always run immediately.

To replicate this issue, create a new Net 8.0 Azure Functions app in Visual Studio and, when prompted, select Function Durable Functions Orchestrations. Update all nuget pacakges. Alter the HttpStart method as follows:

    [Function("ScheduleWorkflow_HttpStart")]
    public static async Task<HttpResponseData> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
        [DurableClient] DurableTaskClient client,
        FunctionContext executionContext)
    {
        ILogger logger = executionContext.GetLogger("ScheduleWorkflow_HttpStart");

        // Function input comes from the request content.
        DateTimeOffset startAt = DateTimeOffset.UtcNow.AddMinutes(10);

        string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
            nameof(Function1),
            new StartOrchestrationOptions { StartAt = startAt });

        logger.LogInformation("Orchestration with ID = '{instanceId}' to be started at {startAt}.", instanceId, startAt);

        // Returns an HTTP 202 response with an instance management payload.
        // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
        return client.CreateCheckStatusResponse(req, instanceId);
    }

The nuget pacakges are as follows:

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.10.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
  </ItemGroup>

The orchestration will run immediately. It should run 10 minutes from making the HTTP request.

This issue was discovered in one of our real function applications. When running that app locally, we looked into the storage emulator (Azurite) and could see that the ScheduleStartTime is not being set.

If we downgrade "Microsoft.Azure.Functions.Worker.Extensions.DurableTask" to version "1.0.0" the schedule feature works.

    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.0.0" />
ChristopherL-STCU commented 7 months ago

I'm experiencing the same issue with v1.1.1. It appears the StartAt issue was introduced between v1.0.3 and v1.0.4 of Microsoft.Azure.Functions.Worker.Extensions.DurableTask.

I need to use v1.1.1 because it contains async versions of methods, such as CreateCheckStatusResponseAsync, which is needed due to this change and which Durable Functions was updated for here. So I'm stuck.

cgillum commented 6 months ago

This looks like a regression caused by #2634. When the code was refactored, the scheduled time information was no longer being propagated to the messaging layer. /cc @jviau

RobARichardson commented 3 months ago

Just stumbled on this issue because I was observing the same behavior. A fix would be much appreciated.

RobARichardson commented 1 month ago

Sorry to nag, but any update on this? Would really like to be able to use this feature.

developmentvegas commented 3 weeks ago

I am using Microsoft.Azure.Functions.Worker.Extensions.DurableTask v1.4, and I am still having this issue. Is there any idea when this will be solved? This has been in P1 for a while without resolution.

tomseida commented 1 week ago

It has been over nine months since this ticket was created noting that ScheduleNewOrchestrationInstanceAsync() is unable to Schedule an orchestration. It makes me wonder if Microsoft is committed to supporting function apps since it is letting this obvious defect linger for so long. Please give the community an update or release the fix!

cgillum commented 1 week ago

Please use https://github.com/Azure/azure-functions-durable-extension/pull/2805 to follow the latest status of this issue.