-
Hi aspire friends. Currently I experiment a bit with the parent feature of Aspire to cleanup our dashboard a bit. (we have in our project around 50 to 100 Resources on the dashboard) Also, I was thinking that this is a good way to remove some of the complexity of the relationships between our resources. So, my goal is to have something like this: We already build for us extensions for the KeyCloak integration to create Realms, Client-Applications and users. The problem is that we first need to wait for KeyCloak to become healthy. If KeyCloak is healthy the realm can be created and after that client applications and the users can be created. Because children cannot be annotated to wait for their parents, I created for the children resources a method that waits for the parent to complete: private async Task WaitForDependencies(IResourceWithWaitSupport resource, CancellationToken cancellationToken)
{
// mark the client application as ready
await _resourceNotificationService.PublishUpdateAsync(resource, s => s with
{
State = KnownResourceStates.Waiting
}).ConfigureAwait(false);
// wait for dependencies to be ready
await _resourceNotificationService.WaitForDependenciesAsync(resource, cancellationToken).ConfigureAwait(false);
await WaitForParents(resource, cancellationToken).ConfigureAwait(true);
// mark the client resource as ready
await _resourceNotificationService.PublishUpdateAsync(resource, s => s with
{
State = KnownResourceStates.Starting
}).ConfigureAwait(false);
}
private async Task WaitForParents(IResource resource, CancellationToken cancellationToken)
{
if (resource is not IResourceWithParent resourceWithParent)
{
await Task.CompletedTask;
return;
}
var taskCollection = new List<Task>();
taskCollection.Add(WaitForParents(resourceWithParent.Parent, cancellationToken));
taskCollection.Add(
_resourceNotificationService.WaitForResourceAsync(
resourceWithParent.Parent.Name,
x => x.Snapshot.State == KnownResourceStates.Running && x.Snapshot.HealthStatus == Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus.Healthy,
cancellationToken: cancellationToken)
);
await Task.WhenAll(taskCollection).ConfigureAwait(true);
} But I still had the issue that resources that had a After some debugging, I realized that in the file That is in my opinion a bit odd behavior, because in all the use cases I can think of, the parent resource needs to be first there and ready before the children can be started. So, my question is: How can I create children of a resource that waits for the parent to be healthy? Or is this excluded by design? Currently related issues: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I wrote this up to explain some of the behavior https://gist.github.com/davidfowl/b408af870d4b5b54a28bf18bffa127e1. |
Beta Was this translation helpful? Give feedback.
I wrote this up to explain some of the behavior https://gist.github.com/davidfowl/b408af870d4b5b54a28bf18bffa127e1.