Skip to main content

RetryHandler

A class in Alta.Api.DataTransferModels, Alta.Api.DataTransferModels.Utility.

HTTP handler for the API client that adds a timeout per attempt and retries failed requests with a doubling delay (2, 4, ... seconds).

Constructors​

MemberWhat it is
RetryHandler(float timeOutInSeconds, int maxRetryAmount = 3)Creates a RetryHandler from timeOutInSeconds and maxRetryAmount.

Fields​

3 private and internal fields
MemberWhat it is
private static readonly Logger LoggerClass logger.
private readonly int maxRetryAmountMost attempts per request; 3 by default.
private readonly TimeSpan timeoutTime allowed for each attempt.

Events​

MemberWhat it is
static event Action<HttpRequestMessage> TimedOutRaised when every attempt at a request timed out. The low-level API client listens to it.

Methods​

MemberWhat it is
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)Sends the request, retrying on timeouts and errors. After the last attempt, errors throw HttpRequestException and timeouts raise TimedOut then throw TimeoutException.
1 private and internal method
MemberWhat it is
private CancellationTokenSource CreateTimeoutTokenSource(CancellationToken cancellationToken)Makes a cancel token that fires after timeout or when the caller cancels.