dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.82k stars 453 forks source link

WaitFor(...): Resource startup sequencing with dependencies #5275

Closed mitchdenny closed 3 weeks ago

mitchdenny commented 2 months ago

The purpose of this issue is to bring together the various threads/issues/discussions about a new API that we want to add to the .NET Aspire AppHost/AppModel that allows developers to express startup dependencies between resources. The most recent spike/prototype of this feature was by @davidfowl here:

https://github.com/davidfowl/WaitForDependenciesAspire/blob/389f02daf2a3903924875c601dc300371aa99e27/WaitForDependencies.AppHost/Program.cs#L19

This issue is not a formal API proposal (we'll create one of those separately). But the high level of the API is this:

public class ResourceBuilderExtensions
{
+ public static IResourceBuilder<T> WaitFor<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> other) where T : IResource
}

This would create a new annotation in the app model which mechanisms like the ApplicationExecutor (internal) would honor (@davidfowl's prototype exploits environment callbacks so we would be shifting to something more explicit).

David's prototype also has a WaitForCompletion(...) method and we are also experimenting with WaitForText(...) APIs in some of our internal testing code which are also good candidates for inclusion in this overall feature.

Finally, we may want this feature to integrate in some way with health checks so that WaitFor(...) ... when health checks are present waits for the checks to become healthy before allowing the dependent resource to start up.

mitchdenny commented 2 months ago

Note that this feature may not ship in 8.2 - work will be done in 8.2 but it probably won't be complete.

mitchdenny commented 2 months ago

There may be some interaction between what we want to do here and #5234 (issue) #5223 (PR).

joperezr commented 2 months ago

@mitchdenny I'm assuming this is not going to make it into 8.2 (meaning it is not blocking)

mitchdenny commented 2 months ago

Not blocking. But we probably want this in for 8.2: https://github.com/dotnet/aspire/pull/5359

JeroMiya commented 2 months ago

The milestone was updated to 9.0 - does that mean it's not going to make it into a LTS version of .NET until Q4 2025? Can we get a backport of the feature for .net 8.0? Many companies have a "LTS only" policy and this feature is a major blocker.

mitchdenny commented 2 months ago

That is the current plan. As we got into this we realized that WaitFor(...) really needs to perform some kind of health check on the resource that was deployed to ensure that its actually available to handle traffic (not just that it merely started).

That means that we need to add health check mechanisms to all of our Aspire.Hosting.* packages which is a big step up in the dependency graph for hosting packages. Its probably not something we would want to rush into an 8.x release or even backport given the some of the churn that would involve.

davidfowl commented 2 months ago

Aspire 9.x is going to be compatible with .NET 8.

mitchdenny commented 1 month ago

Principal feature work for this is now in. We have a few trailing issues:

5469

5557

5558

5569

davidfowl commented 3 weeks ago

This is done

JeroMiya commented 3 weeks ago

Big "Thank you!" to everyone involved in getting this through!

plppp2001 commented 6 days ago

The .WaitFor(...) dependicies will be available in Aspire .net 9 release?

thanks

davidfowl commented 6 days ago

Yes. You can read the 9.0 rc1 docs https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9-release-candidate-1?tabs=windows&pivots=vscode#waiting-for-dependencies