Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 protected internal OperationContext(string operationId, object state, RetryContext retryContext)
 {
     OperationId  = operationId;
     State        = state;
     RetryContext = retryContext;
 }
Esempio n. 4
0
 protected internal OperationContext(object state, RetryContext retryContext)
     : this(Guid.NewGuid().ToString("D"), state, retryContext)
 {
 }
Esempio n. 5
0
 protected virtual Task DelayAsync(RetryContext context, CancellationToken cancellationToken = default)
 {
     return(Task.CompletedTask);
 }
Esempio n. 6
0
 protected override Task DelayAsync(RetryContext context, CancellationToken cancellationToken = default) => Task.Delay(RetryDelays[context.RetryCount], cancellationToken);