Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ResourceNotificationService(ILogger<ResourceNotificationService> logger,
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_serviceProvider = new NullServiceProvider();
_resourceLoggerService = new ResourceLoggerService();
DefaultWaitBehavior = WaitBehavior.StopOnResourceUnavailable;
DefaultWaitBehavior = WaitBehavior.Throw;
}

/// <summary>
Expand All @@ -69,7 +69,7 @@ public ResourceNotificationService(
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_serviceProvider = serviceProvider;
_resourceLoggerService = resourceLoggerService ?? throw new ArgumentNullException(nameof(resourceLoggerService));
DefaultWaitBehavior = serviceProvider.GetService<IOptions<ResourceNotificationServiceOptions>>()?.Value.DefaultWaitBehavior ?? WaitBehavior.StopOnResourceUnavailable;
DefaultWaitBehavior = serviceProvider.GetService<IOptions<ResourceNotificationServiceOptions>>()?.Value.DefaultWaitBehavior ?? WaitBehavior.Throw;

// The IHostApplicationLifetime parameter is not used anymore, but we keep it for backwards compatibility.
// Notification updates will be cancelled when the service is disposed.
Expand Down Expand Up @@ -161,7 +161,7 @@ async Task Core(string displayName, string resourceId)
var resourceEvent = await WaitForResourceCoreAsync(dependency.Name, re => re.ResourceId == resourceId && IsContinuableState(waitBehavior, re.Snapshot), cancellationToken: cancellationToken).ConfigureAwait(false);
var snapshot = resourceEvent.Snapshot;

if (waitBehavior == WaitBehavior.StopOnResourceUnavailable)
if (waitBehavior == WaitBehavior.Throw)
{
if (snapshot.State?.Text == KnownResourceStates.FailedToStart)
{
Expand Down Expand Up @@ -208,8 +208,8 @@ async Task Core(string displayName, string resourceId)
static bool IsContinuableState(WaitBehavior waitBehavior, CustomResourceSnapshot snapshot) =>
waitBehavior switch
{
WaitBehavior.WaitOnResourceUnavailable => snapshot.State?.Text == KnownResourceStates.Running,
WaitBehavior.StopOnResourceUnavailable => snapshot.State?.Text == KnownResourceStates.Running ||
WaitBehavior.Wait => snapshot.State?.Text == KnownResourceStates.Running,
WaitBehavior.Throw => snapshot.State?.Text == KnownResourceStates.Running ||
snapshot.State?.Text == KnownResourceStates.Finished ||
snapshot.State?.Text == KnownResourceStates.Exited ||
snapshot.State?.Text == KnownResourceStates.FailedToStart ||
Expand All @@ -233,7 +233,7 @@ public async Task<ResourceEvent> WaitForResourceHealthyAsync(string resourceName
{
return await WaitForResourceHealthyAsync(
resourceName,
WaitBehavior.WaitOnResourceUnavailable, // Retain default behavior.
WaitBehavior.Wait, // Retain default behavior.
cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -267,8 +267,8 @@ public async Task<ResourceEvent> WaitForResourceHealthyAsync(string resourceName
static bool ShouldYield(WaitBehavior waitBehavior, CustomResourceSnapshot snapshot) =>
waitBehavior switch
{
WaitBehavior.WaitOnResourceUnavailable => snapshot.HealthStatus == HealthStatus.Healthy,
WaitBehavior.StopOnResourceUnavailable => snapshot.HealthStatus == HealthStatus.Healthy ||
WaitBehavior.Wait => snapshot.HealthStatus == HealthStatus.Healthy,
WaitBehavior.Throw => snapshot.HealthStatus == HealthStatus.Healthy ||
snapshot.State?.Text == KnownResourceStates.Finished ||
snapshot.State?.Text == KnownResourceStates.Exited ||
snapshot.State?.Text == KnownResourceStates.FailedToStart ||
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Hosting/ApplicationModel/WaitAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public enum WaitType
public enum WaitBehavior
{
/// <summary>
/// If the resource is unavailable, continue waiting.
/// Wait indefinately.
/// </summary>
WaitOnResourceUnavailable,
Wait,

/// <summary>
/// If the resource is unavailable, stop waiting.
/// Throw if the resource enters a terminal state.
/// </summary>
StopOnResourceUnavailable
Throw
}
Loading