protected override Task DelayAsync(RetryContext context, CancellationToken cancellationToken = default) { var delay = TimeSpan.FromSeconds(BaseDelay.TotalSeconds * Math.Pow(context.RetryCount, ExponentialPower)); if (MaxRetryDelay >= TimeSpan.Zero && delay > MaxRetryDelay) { delay = MaxRetryDelay; } // delay (to the power of 3): 0s, 1s, 8s, 27s, 64s but if max is at 60s, then: ... 27s, 60s, 60s.... return(Task.Delay(delay, cancellationToken)); }
public virtual async Task <bool> CheckRetryAndDelayAsync(RetryContext context, CancellationToken cancellationToken = default) { ArgCheck.NotNull(nameof(context), context); var maxRetryCount = GetMaxRetryCount(); if (maxRetryCount.HasValue && context.RetryCount >= maxRetryCount.Value) { return(false); } await DelayAsync(context, cancellationToken).ConfigureAwait(false); context.RetryCount++; return(true); }
protected internal OperationContext(string operationId, object state, RetryContext retryContext) { OperationId = operationId; State = state; RetryContext = retryContext; }
protected internal OperationContext(object state, RetryContext retryContext) : this(Guid.NewGuid().ToString("D"), state, retryContext) { }
protected virtual Task DelayAsync(RetryContext context, CancellationToken cancellationToken = default) { return(Task.CompletedTask); }
protected override Task DelayAsync(RetryContext context, CancellationToken cancellationToken = default) => Task.Delay(RetryDelays[context.RetryCount], cancellationToken);