Table of Contents

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

options IOptions<GracefulDegradationOptions>

The graceful degradation configuration options.

logger ILogger<GracefulDegradationService>

The logger instance for logging degradation events.

timeProvider TimeProvider

The 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

disposing bool

Indicates whether managed resources should be released.

DisposeAsync()

Asynchronously releases resources, ensuring the health check timer callback has completed.

public ValueTask DisposeAsync()

Returns

ValueTask

ExecuteWithDegradationAsync<T>(DegradationContext<T>, CancellationToken)

Executes an operation with graceful degradation.

public Task<T> ExecuteWithDegradationAsync<T>(DegradationContext<T> context, CancellationToken cancellationToken)

Parameters

context DegradationContext<T>

The degradation context describing fallback strategies.

cancellationToken CancellationToken

A token that is observed for cancellation.

Returns

Task<T>

A task that completes with the operation result.

Type Parameters

T

The 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

level DegradationLevel

The level to apply.

reason string

The reason for the manual override.