8000 WaitFor/WaitForCompletion implementation. by mitchdenny · Pull Request #5394 · dotnet/aspire · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WaitFor/WaitForCompletion implementation. #5394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 30, 2024
Merged

Conversation

mitchdenny
Copy link
Member
@mitchdenny mitchdenny commented Aug 23, 2024

Description

This PR introduces two new extension APIs to the IResourceBuilder<T> interface:

namespace Aspire.Hosting;

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

Using these APIs it is possible to block the start of one resource depending on the start or completion of another resource.

var catalogDbApp = builder.AddProject<Projects.CatalogDb>("catalogdbapp")
                          .WithReference(catalogDb);

var catalogService = builder.AddProject<Projects.CatalogService>("catalogservice")
                            .WithReference(catalogDb)
                            .WithReplicas(2)
                            .WaitForCompletion(catalogDbApp);

The WaitFor(...) extension will wait until the resource enters the Running state, and the WaitForCompletion will wait until it is in the Finished state.

The WaitFor/WaitForCompletion methods build upon the eventing mechanism that was recently added. It waits for the resource started event and then uses the ResourceNotification service to wait until the resource reaches the desired state. In a subsequent PR we will build on this to support waiting until the resource is healthy in addition to just being in a running state.

Resources in a waiting state will have their state changed to Waiting with the same iconography as Starting (hence the small changes to dashboard/known state code).

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Aug 23, 2024
@mitchdenny mitchdenny self-assigned this Aug 23, 2024
@mitchdenny mitchdenny added this to the 9.0 milestone Aug 23, 2024
@mitchdenny
Copy link
Member Author

/azp run

< 8000 /div>

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

Co-authored-by: David Fowler <davidfowl@gmail.com>
@mitchdenny mitchdenny requested a review from davidfowl August 27, 2024 12:02
@mitchdenny
Copy link
Member Author

/azp run

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@radical radical mentioned this pull request Aug 28, 2024
16 tasks
@mitchdenny
Copy link
Member Author

/azp run

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

/// </example>
public static IResourceBuilder<T> WaitFor<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) where T : IResource
{
builder.ApplicationBuilder.Eventing.Subscribe<BeforeResourceStartedEvent>(builder.Resource, async (e, ct) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another downside to doing it this way instead of a single wait for callback with lots of data is that first one to throw will stop other errors from coming through since the wait is sequential.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for this event we should invoke them all in parallel and then await them all together.

@radical
Copy link
Member
radical commented Aug 28, 2024

/azp run

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Member Author

/azp run

Copy link
Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny mitchdenny merged commit 52bc399 into main Aug 30, 2024
11 checks passed
@mitchdenny mitchdenny deleted the mitchdenny/wait-for branch August 30, 2024 03:54
eerhardt added a commit to eerhardt/aspire that referenced this pull request Aug 30, 2024
Follow up feedback for dotnet#5394.
@eerhardt eerhardt mentioned this pull request Aug 30, 2024
davidfowl pushed a commit that referenced this pull request Aug 31, 2024
Follow up feedback for #5394.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0