/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times /// calling <paramref name="onRetry"/> on each retry with the handled exception or result, current sleep duration, retry count, and context data. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than or equal to zero.</exception> /// <exception cref="System.ArgumentNullException"> /// timeSpanProvider /// or /// onRetry /// </exception> public static RetryPolicy <TResult> WaitAndRetry <TResult>(this PolicyBuilder <TResult> policyBuilder, int retryCount, Func <int, Context, TimeSpan> sleepDurationProvider, Action <DelegateResult <TResult>, TimeSpan, int, Context> onRetry) { return(policyBuilder.WaitAndRetry( retryCount, (i, outcome, ctx) => sleepDurationProvider(i, ctx), onRetry )); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry as many times as there are provided <paramref name="sleepDurations"/> /// calling <paramref name="onRetry"/> on each retry with the raised exception, current sleep duration and context data. /// On each retry, the duration to wait is the current <paramref name="sleepDurations"/> item. /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="sleepDurations">The sleep durations to wait for on each retry.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentNullException"> /// sleepDurations /// or /// onRetry /// </exception> public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable <TimeSpan> sleepDurations, Action <Exception, TimeSpan, Context> onRetry) { if (onRetry == null) { throw new ArgumentNullException(nameof(onRetry)); } return(policyBuilder.WaitAndRetry(sleepDurations, (outcome, span, i, ctx) => onRetry(outcome, span, ctx))); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry as many times as there are provided <paramref name="sleepDurations"/> /// calling <paramref name="onRetry"/> on each retry with the handled exception or result and the current sleep duration. /// On each retry, the duration to wait is the current <paramref name="sleepDurations"/> item. /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="sleepDurations">The sleep durations to wait for on each retry.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentNullException"> /// sleepDurations /// or /// onRetry /// </exception> public static RetryPolicy <TResult> WaitAndRetry <TResult>(this PolicyBuilder <TResult> policyBuilder, IEnumerable <TimeSpan> sleepDurations, Action <DelegateResult <TResult>, TimeSpan> onRetry) { if (onRetry == null) { throw new ArgumentNullException(nameof(onRetry)); } return(policyBuilder.WaitAndRetry(sleepDurations, (outcome, span, i, ctx) => onRetry(outcome, span))); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times /// calling <paramref name="onRetry"/> on each retry with the raised exception, current sleep duration, retry count, and context data. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than or equal to zero.</exception> /// <exception cref="System.ArgumentNullException"> /// timeSpanProvider /// or /// onRetry /// </exception> public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func <int, Context, TimeSpan> sleepDurationProvider, Action <Exception, TimeSpan, int, Context> onRetry) { if (sleepDurationProvider == null) { throw new ArgumentNullException(nameof(sleepDurationProvider)); } return(policyBuilder.WaitAndRetry( retryCount, (i, outcome, ctx) => sleepDurationProvider(i, ctx), onRetry)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times /// calling <paramref name="onRetry"/> on each retry with the raised exception and the current sleep duration. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than or equal to zero.</exception> /// <exception cref="System.ArgumentNullException"> /// sleepDurationProvider /// or /// onRetry /// </exception> public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func <int, TimeSpan> sleepDurationProvider, Action <Exception, TimeSpan> onRetry) { if (onRetry == null) { throw new ArgumentNullException(nameof(onRetry)); } return(policyBuilder.WaitAndRetry( retryCount, sleepDurationProvider, (outcome, span, i, ctx) => onRetry(outcome, span) )); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times /// calling <paramref name="onRetry"/> on each retry with the handled exception or result, current sleep duration and context data. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <param name="onRetry">The action to call on each retry.</param> /// <returns>The policy instance.</returns> /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than or equal to zero.</exception> /// <exception cref="System.ArgumentNullException"> /// sleepDurationProvider /// or /// onRetry /// </exception> public static RetryPolicy <TResult> WaitAndRetry <TResult>(this PolicyBuilder <TResult> policyBuilder, int retryCount, Func <int, DelegateResult <TResult>, Context, TimeSpan> sleepDurationProvider, Action <DelegateResult <TResult>, TimeSpan, Context> onRetry) { if (onRetry == null) { throw new ArgumentNullException(nameof(onRetry)); } return(policyBuilder.WaitAndRetry( retryCount, sleepDurationProvider, (outcome, span, i, ctx) => onRetry(outcome, span, ctx) )); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry as many times as there are provided <paramref name="sleepDurations"/> /// On each retry, the duration to wait is the current <paramref name="sleepDurations"/> item. /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="sleepDurations">The sleep durations to wait for on each retry.</param> /// <returns>The policy instance.</returns> public static RetryPolicy <TResult> WaitAndRetry <TResult>(this PolicyBuilder <TResult> policyBuilder, IEnumerable <TimeSpan> sleepDurations) { Action <DelegateResult <TResult>, TimeSpan> doNothing = (_, __) => { }; return(policyBuilder.WaitAndRetry(sleepDurations, doNothing)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <returns>The policy instance.</returns> public static RetryPolicy <TResult> WaitAndRetry <TResult>(this PolicyBuilder <TResult> policyBuilder, int retryCount, Func <int, TimeSpan> sleepDurationProvider) { Action <DelegateResult <TResult>, TimeSpan> doNothing = (_, __) => { }; return(policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, doNothing)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry as many times as there are provided <paramref name="sleepDurations"/> /// On each retry, the duration to wait is the current <paramref name="sleepDurations"/> item. /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="sleepDurations">The sleep durations to wait for on each retry.</param> /// <returns>The policy instance.</returns> public static Policy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable <TimeSpan> sleepDurations) { Action <Exception, TimeSpan> doNothing = (_, __) => { }; return(policyBuilder.WaitAndRetry(sleepDurations, doNothing)); }
/// <summary> /// Builds a <see cref="Policy"/> that will wait and retry <paramref name="retryCount"/> times. /// On each retry, the duration to wait is calculated by calling <paramref name="sleepDurationProvider"/> with /// the current retry attempt allowing an exponentially increasing wait time (exponential backoff). /// </summary> /// <param name="policyBuilder">The policy builder.</param> /// <param name="retryCount">The retry count.</param> /// <param name="sleepDurationProvider">The function that provides the duration to wait for for a particular retry attempt.</param> /// <returns>The policy instance.</returns> public static Policy WaitAndRetry(this PolicyBuilder policyBuilder, int retryCount, Func <int, TimeSpan> sleepDurationProvider) { Action <Exception, TimeSpan> doNothing = (_, __) => { }; return(policyBuilder.WaitAndRetry(retryCount, sleepDurationProvider, doNothing)); }