ResourceNotificationService Methods
DisposeSection titled Disposepublic class ResourceNotificationService{ public void Dispose() { // ... }}PublishUpdateAsync(IResource, string, Func<CustomResourceSnapshot, CustomResourceSnapshot>)Section titled PublishUpdateAsync(IResource, string, Func<CustomResourceSnapshot, CustomResourceSnapshot>)TaskCustomResourceSnapshot for a resource. public class ResourceNotificationService{ public Task PublishUpdateAsync( IResource resource, string resourceId, Func<CustomResourceSnapshot, CustomResourceSnapshot> stateFactory) { // ... }}Parameters
resourceIResourceThe resource to updateresourceIdstring The id of the resource.stateFactoryFunc<CustomResourceSnapshot, CustomResourceSnapshot>A factory that creates the new state based on the previous state.PublishUpdateAsync(IResource, Func<CustomResourceSnapshot, CustomResourceSnapshot>)Section titled PublishUpdateAsync(IResource, Func<CustomResourceSnapshot, CustomResourceSnapshot>)TaskCustomResourceSnapshot for a resource. public class ResourceNotificationService{ public Task PublishUpdateAsync( IResource resource, Func<CustomResourceSnapshot, CustomResourceSnapshot> stateFactory) { // ... }}Parameters
resourceIResourceThe resource to updatestateFactoryFunc<CustomResourceSnapshot, CustomResourceSnapshot>A factory that creates the new state based on the previous state.TryGetCurrentState(string, ResourceEvent?)Section titled TryGetCurrentState(string, ResourceEvent?)boolpublic class ResourceNotificationService{ public bool TryGetCurrentState( string resourceId, out ResourceEvent? resourceEvent) { // ... }}Parameters
resourceIdstringThe resource id. This id can either exactly match the unique id of the resource or the displayed resource name if the resource name doesn't have duplicates (i.e. replicas).resourceEventResourceEvent?When this method returns, contains the ResourceEvent for the specified resource id, if found; otherwise, null.Returns
booltrue if specified resource id was found; otherwise, false.Remarks
A resource id can be either the unique id of the resource or the displayed resource name.
Projects, executables and containers typically have a unique id that combines the display name and a unique suffix. For example, a resource named cache could have a resource id of cache-abcdwxyz. This id is used to uniquely identify the resource in the app host.
The resource name can be also be used to retrieve the resource state, but it must be unique. If there are multiple resources with the same name, then this method will not return a match. For example, if a resource named cache has multiple replicas, then specifing cache won't return a match.
WaitForDependenciesAsync(IResource, CancellationToken)Section titled WaitForDependenciesAsync(IResource, CancellationToken)Taskpublic class ResourceNotificationService{ public Task WaitForDependenciesAsync( IResource resource, CancellationToken cancellationToken) { // ... }}Parameters
resourceIResourceThe resource with dependencies to wait for.cancellationTokenCancellationTokenThe cancellation token.Returns
TaskA task.Exceptions
WaitForResourceAsync(string, string?, CancellationToken)Section titled WaitForResourceAsync(string, string?, CancellationToken)TaskKnownResourceStates for common states. public class ResourceNotificationService{ public Task WaitForResourceAsync( string resourceName, string? targetState = null, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceNamestringThe name of the resource.targetStatestring?optionalThe state to wait for the resource to transition to. See KnownResourceStates for common states.cancellationTokenCancellationTokenoptionalA Threading.CancellationToken.Returns
TaskA Tasks.Task representing the wait operation.Remarks
cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceAsync(string, IEnumerable<string>, CancellationToken)Section titled WaitForResourceAsync(string, IEnumerable<string>, CancellationToken)Task<string>KnownResourceStates for common states. public class ResourceNotificationService{ public Task<string> WaitForResourceAsync( string resourceName, IEnumerable<string> targetStates, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceNamestringThe name of the resource.targetStatesIEnumerable<string>The set of states to wait for the resource to transition to one of. See KnownResourceStates for common states.cancellationTokenCancellationTokenoptionalA cancellation token that cancels the wait operation when signaled.Returns
Task<string>A Tasks.Task`1 representing the wait operation and which of the target states the resource reached.Remarks
cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceAsync(string, Func<ResourceEvent, bool>, CancellationToken)Section titled WaitForResourceAsync(string, Func<ResourceEvent, bool>, CancellationToken)Task<ResourceEvent>public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceAsync( string resourceName, Func<ResourceEvent, bool> predicate, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceNamestringThe name of the resource.predicateFunc<ResourceEvent, bool>A predicate which is evaluated for each ResourceEvent for the selected resource.cancellationTokenCancellationTokenoptionalA cancellation token that cancels the wait operation when signaled.Returns
Task<ResourceEvent>A Tasks.Task`1 representing the wait operation and which of the target states the resource reached.Remarks
true. If the predicate isn't satisfied before cancellationToken is signaled, this method will throw OperationCanceledException. WaitForResourceHealthyAsync(string, CancellationToken)Section titled WaitForResourceHealthyAsync(string, CancellationToken)Task<ResourceEvent>public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceHealthyAsync( string resourceName, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceNamestringThe name of the resource.cancellationTokenCancellationTokenoptionalThe cancellation token.Returns
Task<ResourceEvent>A task.Remarks
This method returns a task that will complete with the resource is healthy. A resource without HealthCheckAnnotation annotations will be considered healthy once it reaches a KnownResourceStates.Running state.
If the resource enters an unavailable state such as KnownResourceStates.FailedToStart then this method will continue to wait to enable scenarios where a resource could be restarted and recover. To control this behavior use ResourceNotificationService.WaitForResourceHealthyAsync or configure the default behavior with ResourceNotificationServiceOptions.DefaultWaitBehavior.
WaitForResourceHealthyAsync(string, WaitBehavior, CancellationToken)Section titled WaitForResourceHealthyAsync(string, WaitBehavior, CancellationToken)Task<ResourceEvent>public class ResourceNotificationService{ public Task<ResourceEvent> WaitForResourceHealthyAsync( string resourceName, WaitBehavior waitBehavior, CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
resourceNamestringThe name of the resource.waitBehaviorWaitBehaviorThe wait behavior.cancellationTokenCancellationTokenoptionalThe cancellation token.Returns
Task<ResourceEvent>A task.Remarks
This method returns a task that will complete with the resource is healthy. A resource without HealthCheckAnnotation annotations will be considered healthy once it reaches a KnownResourceStates.Running state. The WaitBehavior controls how the wait operation behaves when the resource enters an unavailable state such as KnownResourceStates.FailedToStart.
When WaitBehavior.WaitOnResourceUnavailable is specified the wait operation will continue to wait until the resource reaches a KnownResourceStates.Running state.
When WaitBehavior.StopOnResourceUnavailable is specified the wait operation will throw a DistributedApplicationException if the resource enters an unavailable state.
WatchAsync(CancellationToken)Section titled WatchAsync(CancellationToken)IAsyncEnumerable<ResourceEvent>public class ResourceNotificationService{ public IAsyncEnumerable<ResourceEvent> WatchAsync( CancellationToken cancellationToken = default(CancellationToken)) { // ... }}Parameters
cancellationTokenCancellationTokenoptional