/// <summary> /// Creates a new instance with the specified settings. /// </summary> /// <param name="delay">The initial delay, either for the first retry or as the initial RPC timeout.</param> /// <param name="maxDelay">The maximum delay to use. If the increasing delay due to the delay multiplier exceeds this, /// this maximum is used instead.</param> /// <param name="delayMultiplier">The multiplier to apply to the delay on each iteration; must be greater than or equal to 1.0. /// Defaults to 1.0.</param> public BackoffSettings(TimeSpan delay, TimeSpan maxDelay, double delayMultiplier = 1.0) { GaxPreconditions.CheckNonNegativeDelay(delay, nameof(delay)); GaxPreconditions.CheckNonNegativeDelay(maxDelay, nameof(maxDelay)); if (delayMultiplier < 1.0 || double.IsNaN(delayMultiplier)) { throw new ArgumentOutOfRangeException(nameof(delayMultiplier), delayMultiplier, "Delay multiplier must be a real number greater than or equal to 1"); } Delay = delay; MaxDelay = maxDelay; DelayMultiplier = delayMultiplier; }
/// <summary> /// Creates a new instance with the given settings. /// </summary> /// <param name="maxAttempts">The maximum number of attempts to make. Must be positive.</param> /// <param name="initialBackoff">The backoff after the initial failure. Must be non-negative.</param> /// <param name="maxBackoff">The maximum backoff. Must be at least <paramref name="initialBackoff"/>.</param> /// <param name="backoffMultiplier">The multiplier to apply to backoff times. Must be at least 1.0.</param> /// <param name="retryFilter">The predicate to use to check whether an error should be retried. Must not be null.</param> /// <param name="backoffJitter">The jitter to use on each backoff. Must not be null.</param> internal RetrySettings( int maxAttempts, TimeSpan initialBackoff, TimeSpan maxBackoff, double backoffMultiplier, Predicate <Exception> retryFilter, IJitter backoffJitter) { MaxAttempts = GaxPreconditions.CheckArgumentRange(maxAttempts, nameof(maxAttempts), 1, int.MaxValue); InitialBackoff = GaxPreconditions.CheckNonNegativeDelay(initialBackoff, nameof(initialBackoff)); MaxBackoff = GaxPreconditions.CheckNonNegativeDelay(maxBackoff, nameof(maxBackoff)); GaxPreconditions.CheckArgument(maxBackoff >= initialBackoff, nameof(maxBackoff), "Maximum backoff must be at least as large as initial backoff"); BackoffMultiplier = GaxPreconditions.CheckArgumentRange(backoffMultiplier, nameof(backoffMultiplier), 1.0, double.MaxValue); RetryFilter = GaxPreconditions.CheckNotNull(retryFilter, nameof(retryFilter)); BackoffJitter = GaxPreconditions.CheckNotNull(backoffJitter, nameof(backoffJitter)); }
private static RetrySettings ConstantBackoff(int maxAttempts, TimeSpan backoff, Predicate <Exception> retryFilter) { GaxPreconditions.CheckNonNegativeDelay(backoff, nameof(backoff)); return(new RetrySettings(maxAttempts, backoff, backoff, 1.0, retryFilter, RetrySettings.NoJitter)); }