Beispiel #1
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will wait and retry indefinitely.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param>
        /// <returns>The policy instance.</returns>
        /// <exception cref="System.ArgumentNullException">sleepDurationProvider</exception>
        public static RetryPolicy <TResult> WaitAndRetryForever <TResult>(this PolicyBuilder <TResult> policyBuilder, Func <int, TimeSpan> sleepDurationProvider)
        {
            if (sleepDurationProvider == null)
            {
                throw new ArgumentNullException("sleepDurationProvider");
            }

            Action <DelegateResult <TResult>, TimeSpan> doNothing = (_, __) => { };

            return(policyBuilder.WaitAndRetryForever(sleepDurationProvider, doNothing));
        }
Beispiel #2
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will wait and retry indefinitely until the action succeeds,
 /// calling <paramref name="onRetry"/> on each retry with the raised exception and
 /// execution context.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="sleepDurationProvider">A function providing the duration to wait before retrying.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="System.ArgumentNullException">sleepDurationProvider</exception>
 /// <exception cref="System.ArgumentNullException">onRetry</exception>
 public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func <int, Context, TimeSpan> sleepDurationProvider, Action <Exception, TimeSpan, Context> onRetry)
 {
     if (sleepDurationProvider == null)
     {
         throw new ArgumentNullException(nameof(sleepDurationProvider));
     }
     return(policyBuilder.WaitAndRetryForever(
                (i, outcome, ctx) => sleepDurationProvider(i, ctx),
                onRetry
                ));
 }
Beispiel #3
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will wait and retry indefinitely until the action succeeds.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param>
        /// <returns>The policy instance.</returns>
        /// <exception cref="System.ArgumentNullException">sleepDurationProvider</exception>
        public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func <int, Context, TimeSpan> sleepDurationProvider)
        {
            if (sleepDurationProvider == null)
            {
                throw new ArgumentNullException(nameof(sleepDurationProvider));
            }

            Action <Exception, TimeSpan, Context> doNothing = (_, __, ___) => { };

            return(policyBuilder.WaitAndRetryForever(sleepDurationProvider, doNothing));
        }
Beispiel #4
0
 /// <summary>
 /// Builds a <see cref="Policy{TResult}"/> that will wait and retry indefinitely until the action succeeds,
 /// calling <paramref name="onRetry"/> on each retry with the handled exception or result, retry count and execution context.
 ///     On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider" /> with
 ///     the current retry number (1 for first retry, 2 for second etc) and execution context.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="sleepDurationProvider">A function providing the duration to wait before retrying.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="ArgumentNullException">sleepDurationProvider</exception>
 /// <exception cref="ArgumentNullException">onRetry</exception>
 public static RetryPolicy <TResult> WaitAndRetryForever <TResult>(this PolicyBuilder <TResult> policyBuilder, Func <int, Context, TimeSpan> sleepDurationProvider, Action <DelegateResult <TResult>, int, TimeSpan, Context> onRetry)
 {
     if (sleepDurationProvider == null)
     {
         throw new ArgumentNullException(nameof(sleepDurationProvider));
     }
     return(policyBuilder.WaitAndRetryForever(
                (i, _, ctx) => sleepDurationProvider(i, ctx),
                onRetry
                ));
 }
Beispiel #5
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will wait and retry indefinitely until the action succeeds,
        /// calling <paramref name="onRetry"/> on each retry with the raised exception.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="sleepDurationProvider">A function providing the duration to wait before retrying.</param>
        /// <param name="onRetry">The action to call on each retry.</param>
        /// <returns>The policy instance.</returns>
        /// <exception cref="System.ArgumentNullException">sleepDurationProvider</exception>
        /// <exception cref="System.ArgumentNullException">onRetry</exception>
        public static RetryPolicy WaitAndRetryForever(this PolicyBuilder policyBuilder, Func <int, TimeSpan> sleepDurationProvider, Action <Exception, TimeSpan> onRetry)
        {
            if (sleepDurationProvider == null)
            {
                throw new ArgumentNullException(nameof(sleepDurationProvider));
            }
            if (onRetry == null)
            {
                throw new ArgumentNullException(nameof(onRetry));
            }

            return(policyBuilder.WaitAndRetryForever(
                       (retryCount, context) => sleepDurationProvider(retryCount),
                       (exception, timespan, context) => onRetry(exception, timespan)
                       ));
        }
        /// <summary>
        /// Builds a <see cref="Policy"/> that will wait and retry indefinitely until the action succeeds,
        /// calling <paramref name="onRetry"/> on each retry with the handled exception or result and retry count.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="sleepDurationProvider">A function providing the duration to wait before retrying.</param>
        /// <param name="onRetry">The action to call on each retry.</param>
        /// <returns>The policy instance.</returns>
        /// <exception cref="System.ArgumentNullException">sleepDurationProvider</exception>
        /// <exception cref="System.ArgumentNullException">onRetry</exception>
        public static RetryPolicy <TResult> WaitAndRetryForever <TResult>(this PolicyBuilder <TResult> policyBuilder, Func <int, TimeSpan> sleepDurationProvider, Action <DelegateResult <TResult>, int, TimeSpan> onRetry)
        {
            if (sleepDurationProvider == null)
            {
                throw new ArgumentNullException(nameof(sleepDurationProvider));
            }
            if (onRetry == null)
            {
                throw new ArgumentNullException(nameof(onRetry));
            }

            return(policyBuilder.WaitAndRetryForever(
                       (retryCount, outcome, context) => sleepDurationProvider(retryCount),
                       (outcome, i, timespan, context) => onRetry(outcome, i, timespan)
                       ));
        }