-
Notifications
You must be signed in to change notification settings - Fork 649
Remove dependencies on AfterEndpointsAllocatedEvent #9598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5570f68
52f1275
30ae0e9
dba5856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ public ApplicationOrchestrator(DistributedApplicationModel model, | |
dcpExecutorEvents.Subscribe<OnResourceStartingContext>(OnResourceStarting); | ||
dcpExecutorEvents.Subscribe<OnResourceFailedToStartContext>(OnResourceFailedToStart); | ||
|
||
_eventing.Subscribe<AfterEndpointsAllocatedEvent>(ProcessResourcesWithoutLifetime); | ||
_eventing.Subscribe<ResourceEndpointsAllocatedEvent>(ProcessResourcesWithoutLifetime); | ||
_eventing.Subscribe<ResourceEndpointsAllocatedEvent>(PublishInitialResourceUrls); | ||
// Implement WaitFor functionality using BeforeResourceStartedEvent. | ||
_eventing.Subscribe<BeforeResourceStartedEvent>(WaitForInBeforeResourceStartedEvent); | ||
|
@@ -94,7 +94,9 @@ private async Task WaitForInBeforeResourceStartedEvent(BeforeResourceStartedEven | |
|
||
private async Task OnEndpointsAllocated(OnEndpointsAllocatedContext context) | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
var afterEndpointsAllocatedEvent = new AfterEndpointsAllocatedEvent(_serviceProvider, _model); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
await _eventing.PublishAsync(afterEndpointsAllocatedEvent, context.CancellationToken).ConfigureAwait(false); | ||
|
||
foreach (var lifecycleHook in _lifecycleHooks) | ||
|
@@ -240,48 +242,45 @@ private async Task ProcessUrls(IResource resource, CancellationToken cancellatio | |
} | ||
} | ||
|
||
private Task ProcessResourcesWithoutLifetime(AfterEndpointsAllocatedEvent @event, CancellationToken cancellationToken) | ||
private async Task ProcessResourcesWithoutLifetime(ResourceEndpointsAllocatedEvent @event, CancellationToken cancellationToken) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a sketchiest change 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s definitely the one that stood out the most, but at least with the current event behavior/timing it should behave the same. |
||
{ | ||
async Task ProcessValueAsync(IResource resource, IValueProvider vp) | ||
if (@event.Resource is not IResourceWithoutLifetime resource) | ||
{ | ||
try | ||
{ | ||
var value = await vp.GetValueAsync(default).ConfigureAwait(false); | ||
|
||
await _notificationService.PublishUpdateAsync(resource, s => | ||
{ | ||
return s with | ||
{ | ||
Properties = s.Properties.SetResourceProperty("Value", value ?? "", resource is ParameterResource p && p.Secret) | ||
}; | ||
}) | ||
.ConfigureAwait(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await _notificationService.PublishUpdateAsync(resource, s => | ||
{ | ||
return s with | ||
{ | ||
State = new("Value missing", KnownResourceStateStyles.Error), | ||
Properties = s.Properties.SetResourceProperty("Value", ex.Message) | ||
}; | ||
}) | ||
.ConfigureAwait(false); | ||
return; | ||
} | ||
|
||
_loggerService.GetLogger(resource.Name).LogError("{Message}", ex.Message); | ||
} | ||
if (resource is not IValueProvider valueProvider) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var resource in _model.Resources.OfType<IResourceWithoutLifetime>()) | ||
try | ||
{ | ||
if (resource is IValueProvider provider) | ||
var value = await valueProvider.GetValueAsync(default).ConfigureAwait(false); | ||
|
||
await _notificationService.PublishUpdateAsync(resource, s => | ||
{ | ||
_ = ProcessValueAsync(resource, provider); | ||
} | ||
return s with | ||
{ | ||
Properties = s.Properties.SetResourceProperty("Value", value ?? "", resource is ParameterResource p && p.Secret) | ||
}; | ||
}) | ||
.ConfigureAwait(false); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await _notificationService.PublishUpdateAsync(resource, s => | ||
{ | ||
return s with | ||
{ | ||
State = new("Value missing", KnownResourceStateStyles.Error), | ||
Properties = s.Properties.SetResourceProperty("Value", ex.Message) | ||
}; | ||
}) | ||
.ConfigureAwait(false); | ||
|
||
return Task.CompletedTask; | ||
_loggerService.GetLogger(resource.Name).LogError("{Message}", ex.Message); | ||
} | ||
} | ||
|
||
private async Task OnResourceChanged(OnResourceChangedContext context) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aaronontheweb @Alirexaa big change coming.