Skip to content

Commit

Permalink
Add IResourceWithWaitSupport. (#6145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchdenny authored Oct 7, 2024
1 parent 4ce38e3 commit a8b1a61
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/ApplicationModel/ContainerResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="entrypoint">An optional container entrypoint.</param>
public class ContainerResource(string name, string? entrypoint = null) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints
public class ContainerResource(string name, string? entrypoint = null) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
{
/// <summary>
/// The container Entrypoint.
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/ApplicationModel/ExecutableResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// <param name="name">The name of the resource.</param>
/// <param name="command">The command to execute.</param>
/// <param name="workingDirectory">The working directory of the executable.</param>
public class ExecutableResource(string name, string command, string workingDirectory) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints
public class ExecutableResource(string name, string command, string workingDirectory) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
{
/// <summary>
/// Gets the command associated with this executable resource.
Expand Down
11 changes: 11 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/IResourceWithWaitSupport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// Represents a resource that can wait for other resources to be running, health, and/or completed.
/// </summary>
public interface IResourceWithWaitSupport : IResource
{
}
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/ApplicationModel/ProjectResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// A resource that represents a specified .NET project.
/// </summary>
/// <param name="name">The name of the resource.</param>
public class ProjectResource(string name) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithServiceDiscovery
public class ProjectResource(string name) : Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithServiceDiscovery, IResourceWithWaitSupport
{
// Keep track of the config host for each Kestrel endpoint annotation
internal Dictionary<EndpointAnnotation, string> KestrelEndpointAnnotationHosts { get; } = new();
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Aspire.Hosting.ApplicationModel.ExecuteCommandResult.Success.init -> void
Aspire.Hosting.ApplicationModel.HealthCheckAnnotation
Aspire.Hosting.ApplicationModel.HealthCheckAnnotation.HealthCheckAnnotation(string! key) -> void
Aspire.Hosting.ApplicationModel.HealthCheckAnnotation.Key.get -> string!
Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport
Aspire.Hosting.ApplicationModel.ResourceCommandAnnotation.ConfirmationMessage.get -> string?
Aspire.Hosting.ApplicationModel.ResourceCommandAnnotation.DisplayDescription.get -> string?
Aspire.Hosting.ApplicationModel.ResourceCommandAnnotation.Parameter.get -> object?
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Hosting/ResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public static IResourceBuilder<T> ExcludeFromManifest<T>(this IResourceBuilder<T
/// .WaitFor(messaging);
/// </code>
/// </example>
public static IResourceBuilder<T> WaitFor<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) where T : IResource
public static IResourceBuilder<T> WaitFor<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) where T : IResourceWithWaitSupport
{
if (builder.Resource as IResource == dependency.Resource)
{
Expand Down Expand Up @@ -646,7 +646,7 @@ public static IResourceBuilder<T> WaitFor<T>(this IResourceBuilder<T> builder, I
/// .WaitForCompletion(dbprep);
/// </code>
/// </example>
public static IResourceBuilder<T> WaitForCompletion<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, int exitCode = 0) where T : IResource
public static IResourceBuilder<T> WaitForCompletion<T>(this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, int exitCode = 0) where T : IResourceWithWaitSupport
{
if (builder.Resource as IResource == dependency.Resource)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public async Task VerifyWaitForOnCosmosDBEmulatorBlocksDependentResources()
.RunAsEmulator()
.WithHealthCheck("blocking_check");

var dependentResource = builder.AddAzureCosmosDB("dependentresource")
.RunAsEmulator()
var dependentResource = builder.AddContainer("nginx", "mcr.microsoft.com/cbl-mariner/base/nginx", "1.22")
.WaitFor(resource);

using var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public async Task VerifyWaitForOnAzureStorageEmulatorForBlobsBlocksDependentReso
var queues = storage.AddQueues("queues");
var tables = storage.AddTables("tables");

var dependentResource = builder.AddAzureCosmosDB("dependentresource")
.RunAsEmulator()
var dependentResource = builder.AddContainer("nginx", "mcr.microsoft.com/cbl-mariner/base/nginx", "1.22")
.WaitFor(blobs)
.WaitFor(queues)
.WaitFor(tables);
Expand Down
4 changes: 2 additions & 2 deletions tests/Aspire.Hosting.Tests/WaitForTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ public void WaitForOnChildResourceAddsWaitAnnotationPointingToParent()
);
}

private sealed class CustomChildResource(string name, CustomResource parent) : Resource(name), IResourceWithParent<CustomResource>
private sealed class CustomChildResource(string name, CustomResource parent) : Resource(name), IResourceWithParent<CustomResource>, IResourceWithWaitSupport
{
public CustomResource Parent => parent;
}

private sealed class CustomResource(string name) : Resource(name), IResourceWithConnectionString
private sealed class CustomResource(string name) : Resource(name), IResourceWithConnectionString, IResourceWithWaitSupport
{
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create($"foo");
}
Expand Down

0 comments on commit a8b1a61

Please sign in to comment.