Class GracefulDegradationService
- Namespace
- Excalibur.Dispatch.Resilience.Polly
- Assembly
- Excalibur.Dispatch.Resilience.Polly.dll
Implementation of graceful degradation service.
public class GracefulDegradationService : IGracefulDegradationService, IDisposable, IAsyncDisposable
- Inheritance
-
GracefulDegradationService
- Implements
- Inherited Members
- Extension Methods
Constructors
GracefulDegradationService(IOptions<GracefulDegradationOptions>, ILogger<GracefulDegradationService>, TimeProvider?)
Initializes a new instance of the GracefulDegradationService class.
public GracefulDegradationService(IOptions<GracefulDegradationOptions> options, ILogger<GracefulDegradationService> logger, TimeProvider? timeProvider = null)
Parameters
optionsIOptions<GracefulDegradationOptions>The graceful degradation configuration options.
loggerILogger<GracefulDegradationService>The logger instance for logging degradation events.
timeProviderTimeProviderThe clock the degradation decisions are made against. Defaults to System. The rolling error window, the CPU-sample elapsed delta and the health-check cadence all read it, so supplying a controllable provider is what makes a level change reachable without waiting for one.
Properties
CurrentLevel
Gets the current degradation level.
public DegradationLevel CurrentLevel { get; }
Property Value
- DegradationLevel
The active degradation level for the service.
Methods
Dispose()
Disposes the service.
public void Dispose()
Dispose(bool)
Releases managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingboolIndicates whether managed resources should be released.
DisposeAsync()
Asynchronously releases resources, ensuring the health check timer callback has completed.
public ValueTask DisposeAsync()
Returns
ExecuteWithDegradationAsync<T>(DegradationContext<T>, CancellationToken)
Executes an operation with graceful degradation.
public Task<T> ExecuteWithDegradationAsync<T>(DegradationContext<T> context, CancellationToken cancellationToken)
Parameters
contextDegradationContext<T>The degradation context describing fallback strategies.
cancellationTokenCancellationTokenA token that is observed for cancellation.
Returns
- Task<T>
A task that completes with the operation result.
Type Parameters
TThe type returned by the primary or fallback operations.
GetMetrics()
Gets degradation metrics.
public DegradationMetrics GetMetrics()
Returns
- DegradationMetrics
The current degradation metrics.
SetLevel(DegradationLevel, string)
Manually sets the degradation level.
public void SetLevel(DegradationLevel level, string reason)
Parameters
levelDegradationLevelThe level to apply.
reasonstringThe reason for the manual override.