You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// Waits for all resources in the application to become healthy./// </summary>publicstaticasyncTaskWaitForResourcesHealthyAsync(thisDistributedApplicationapp,CancellationTokencancellationToken=default){varlogger=app.Services.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(WaitForResourcesAsync));varapplicationModel=app.Services.GetRequiredService<DistributedApplicationModel>();varresourceNotificationService=app.Services.GetRequiredService<ResourceNotificationService>();varresourceTasks=newDictionary<string,Task<(stringName,stringState)>>();foreach(varresourceinapplicationModel.Resources){resourceTasks[resource.Name]=GetResourceWaitTask(resource.Name,cancellationToken);}logger.LogInformation("Waiting for resources [{Resources}] to become healthy.",string.Join(',',resourceTasks.Keys));while(resourceTasks.Count>0){varcompletedTask=awaitTask.WhenAny(resourceTasks.Values);var(completedResourceName,targetStateReached)=awaitcompletedTask;if(targetStateReached==KnownResourceStates.FailedToStart){thrownewDistributedApplicationException($"Resource '{completedResourceName}' failed to start.");}resourceTasks.Remove(completedResourceName);logger.LogInformation("Wait for resource '{ResourceName}' completed with state '{ResourceState}'",completedResourceName,targetStateReached);// Ensure resources being waited on still existvarremainingResources=resourceTasks.Keys.ToList();for(vari=remainingResources.Count-1;i>0;i--){varname=remainingResources[i];if(!applicationModel.Resources.Any(r =>r.Name==name)){logger.LogInformation("Resource '{ResourceName}' was deleted while waiting for it.",name);resourceTasks.Remove(name);remainingResources.RemoveAt(i);}}if(resourceTasks.Count>0){logger.LogInformation("Still waiting for resources [{Resources}] to become healthy.",string.Join(',',remainingResources));}}logger.LogInformation("Wait for all resources completed successfully!");asyncTask<(stringName,stringState)>GetResourceWaitTask(stringresourceName,CancellationTokencancellationToken){varresourceEvent=awaitresourceNotificationService.WaitForResourceHealthyAsync(resourceName,cancellationToken);return(resourceName,resourceEvent.Snapshot?.State?.Text??"Unknown");}}
The text was updated successfully, but these errors were encountered:
From PR comment #521 (comment)
The text was updated successfully, but these errors were encountered: