diff --git a/src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs b/src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs index 7648f7526cd..5cc446ff43b 100644 --- a/src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs +++ b/src/Aspire.Hosting/ApplicationModel/CommandsConfigurationExtensions.cs @@ -31,11 +31,12 @@ internal static void AddLifeCycleCommands(this IResource resource) }, updateState: context => { - if (IsStarting(context.ResourceSnapshot.State?.Text) || IsWaiting(context.ResourceSnapshot.State?.Text)) + var state = context.ResourceSnapshot.State?.Text; + if (IsStarting(state) || IsRuntimeUnhealthy(state)) { return ResourceCommandState.Disabled; } - else if (IsStopped(context.ResourceSnapshot.State?.Text)) + else if (IsStopped(state) || IsWaiting(state)) { return ResourceCommandState.Enabled; } @@ -63,11 +64,12 @@ internal static void AddLifeCycleCommands(this IResource resource) }, updateState: context => { - if (IsStopping(context.ResourceSnapshot.State?.Text)) + var state = context.ResourceSnapshot.State?.Text; + if (IsStopping(state)) { return ResourceCommandState.Disabled; } - else if (!IsStopped(context.ResourceSnapshot.State?.Text) && !IsStarting(context.ResourceSnapshot.State?.Text) && !IsWaiting(context.ResourceSnapshot.State?.Text) && context.ResourceSnapshot.State is not null) + else if (!IsStopped(state) && !IsStarting(state) && !IsWaiting(state) && !IsRuntimeUnhealthy(state) && context.ResourceSnapshot.State is not null) { return ResourceCommandState.Enabled; } @@ -96,7 +98,8 @@ internal static void AddLifeCycleCommands(this IResource resource) }, updateState: context => { - if (IsWaiting(context.ResourceSnapshot.State?.Text) || IsStarting(context.ResourceSnapshot.State?.Text) || IsStopping(context.ResourceSnapshot.State?.Text) || IsStopped(context.ResourceSnapshot.State?.Text) || context.ResourceSnapshot.State is null) + var state = context.ResourceSnapshot.State?.Text; + if (IsStarting(state) || IsStopping(state) || IsStopped(state) || IsWaiting(state) || IsRuntimeUnhealthy(state) || context.ResourceSnapshot.State is null) { return ResourceCommandState.Disabled; } @@ -115,6 +118,7 @@ internal static void AddLifeCycleCommands(this IResource resource) static bool IsStopped(string? state) => state is "Exited" or "Finished" or "FailedToStart"; static bool IsStopping(string? state) => state is "Stopping"; static bool IsStarting(string? state) => state is "Starting"; - static bool IsWaiting(string? state) => state is "Waiting" or "RuntimeUnhealthy"; + static bool IsWaiting(string? state) => state is "Waiting"; + static bool IsRuntimeUnhealthy(string? state) => state is "RuntimeUnhealthy"; } } diff --git a/tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs b/tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs index e2f45ad4ae6..b2634cbeda0 100644 --- a/tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs +++ b/tests/Aspire.Hosting.Tests/ResourceCommandAnnotationTests.cs @@ -15,7 +15,7 @@ public class ResourceCommandAnnotationTests [InlineData(CommandsConfigurationExtensions.StartCommandName, "Exited", ResourceCommandState.Enabled)] [InlineData(CommandsConfigurationExtensions.StartCommandName, "Finished", ResourceCommandState.Enabled)] [InlineData(CommandsConfigurationExtensions.StartCommandName, "FailedToStart", ResourceCommandState.Enabled)] - [InlineData(CommandsConfigurationExtensions.StartCommandName, "Waiting", ResourceCommandState.Disabled)] + [InlineData(CommandsConfigurationExtensions.StartCommandName, "Waiting", ResourceCommandState.Enabled)] [InlineData(CommandsConfigurationExtensions.StartCommandName, "RuntimeUnhealthy", ResourceCommandState.Disabled)] [InlineData(CommandsConfigurationExtensions.StopCommandName, "Starting", ResourceCommandState.Hidden)] [InlineData(CommandsConfigurationExtensions.StopCommandName, "Stopping", ResourceCommandState.Disabled)]