Skip to content

Commit

Permalink
Post updates using NotificationService from the ApplicationExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Mar 2, 2024
1 parent cf4fce3 commit bd6818e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/Aspire.Hosting/Dashboard/DcpDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,40 @@ bool IsFilteredResource<T>(T resource) where T : CustomResource
}
}

private async Task ProcessInitialResourceAsync(IResource resource, CancellationToken cancellationToken)
private Task ProcessInitialResourceAsync(IResource resource, CancellationToken cancellationToken)
{
// The initial snapshots are all generic resources until we get the real state from DCP (for projects, containers and executables).

if (resource.IsContainer())
{
var snapshot = CreateResourceSnapshot(resource, DateTime.UtcNow, new CustomResourceSnapshot
{
ResourceType = KnownResourceTypes.Container,
Properties = [],
State = "Starting"
});

_placeHolderResources.TryAdd(resource.Name, snapshot);

await _onResourceChanged(snapshot, ResourceSnapshotChangeType.Upsert).ConfigureAwait(false);
}
else if (resource is ProjectResource)
{
var snapshot = CreateResourceSnapshot(resource, DateTime.UtcNow, new CustomResourceSnapshot
{
ResourceType = KnownResourceTypes.Project,
Properties = [],
State = "Starting"
});

_placeHolderResources.TryAdd(resource.Name, snapshot);

await _onResourceChanged(snapshot, ResourceSnapshotChangeType.Upsert).ConfigureAwait(false);
}
else if (resource is ExecutableResource)
{
var snapshot = CreateResourceSnapshot(resource, DateTime.UtcNow, new CustomResourceSnapshot
{
ResourceType = KnownResourceTypes.Executable,
Properties = [],
State = "Starting"
});

_placeHolderResources.TryAdd(resource.Name, snapshot);

await _onResourceChanged(snapshot, ResourceSnapshotChangeType.Upsert).ConfigureAwait(false);
}

var creationTimestamp = DateTime.UtcNow;

_ = Task.Run(async () =>
Expand All @@ -178,6 +168,8 @@ private async Task ProcessInitialResourceAsync(IResource resource, CancellationT
}
}, cancellationToken);

return Task.CompletedTask;
}

private static GenericResourceSnapshot CreateResourceSnapshot(IResource resource, DateTime creationTimestamp, CustomResourceSnapshot snapshot)
Expand Down
17 changes: 17 additions & 0 deletions src/Aspire.Hosting/Dcp/ApplicationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Sockets;
using Aspire.Dashboard.Model;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Dcp.Model;
using Aspire.Hosting.Lifecycle;
Expand Down Expand Up @@ -521,6 +522,14 @@ async Task CreateExecutableAsyncCore(AppResource cr, CancellationToken cancellat
{
var logger = loggerService.GetLogger(cr.ModelResource);

await notificationService.PublishUpdateAsync(cr.ModelResource, s => s with
{
ResourceType = cr.ModelResource is ProjectResource ? KnownResourceTypes.Project : KnownResourceTypes.Executable,
Properties = [],
State = "Starting"
})
.ConfigureAwait(false);

try
{
await CreateExecutableAsync(cr, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -773,6 +782,14 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati
{
var logger = loggerService.GetLogger(cr.ModelResource);

await notificationService.PublishUpdateAsync(cr.ModelResource, s => s with
{
State = "Starting",
Properties = [], // TODO: Add image name
ResourceType = KnownResourceTypes.Container
})
.ConfigureAwait(false);

try
{
await CreateContainerAsync(cr, cancellationToken).ConfigureAwait(false);
Expand Down

0 comments on commit bd6818e

Please sign in to comment.