Show / Hide Table of Contents

Class RetryAttempt

An attempt at a retriable operation. Use CreateRetrySequence(RetrySettings, IScheduler, Nullable<DateTime>, IClock, Nullable<TimeSpan>) or CreateRetrySequence(RetrySettings, IScheduler, Nullable<TimeSpan>) to create a sequence of attempts that follow the specified settings.

Inheritance
System.Object
RetryAttempt
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Api.Gax.Grpc
Assembly: Google.Api.Gax.Grpc.dll
Syntax
public sealed class RetryAttempt

Properties

AttemptNumber

The 1-based number of this attempt. If this is equal to MaxAttempts for the settings used to create this attempt, ShouldRetry(Exception) will always return false.

Declaration
public int AttemptNumber { get; }
Property Value
Type Description
System.Int32

JitteredBackoff

The time that will be used to sleep or delay in Backoff(CancellationToken) and BackoffAsync(CancellationToken). This has already had jitter applied to it.

Declaration
public TimeSpan JitteredBackoff { get; }
Property Value
Type Description
System.TimeSpan

Methods

Backoff(CancellationToken)

Synchronously sleeps for a period of JitteredBackoff.

Declaration
public void Backoff(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

The cancellation token to apply to the sleep operation.

BackoffAsync(CancellationToken)

Asynchronously delays for a period of JitteredBackoff.

Declaration
public Task BackoffAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

The cancellation token to apply to the delay operation.

Returns
Type Description
System.Threading.Tasks.Task

CreateRetrySequence(RetrySettings, IScheduler, Nullable<DateTime>, IClock, Nullable<TimeSpan>)

Returns a sequence of retry attempts. The sequence has MaxAttempts elements, and calling ShouldRetry(Exception) on the last attempt will always return false.

Declaration
public static IEnumerable<RetryAttempt> CreateRetrySequence(RetrySettings settings, IScheduler scheduler, DateTime? deadline, IClock clock, TimeSpan? initialBackoffOverride = default(TimeSpan? ))
Parameters
Type Name Description
RetrySettings settings

The retry settings to create a sequence for. Must not be null.

IScheduler scheduler

The scheduler to use for delays.

System.Nullable<System.DateTime> deadline

The overall deadline for the operation.

IClock clock

The clock to use to compare the current time with the deadline.

System.Nullable<System.TimeSpan> initialBackoffOverride

An override value to allow an initial backoff which is not the same as InitialBackoff. This is typically to allow an "immediate first retry".

Returns
Type Description
System.Collections.Generic.IEnumerable<RetryAttempt>

CreateRetrySequence(RetrySettings, IScheduler, Nullable<TimeSpan>)

Returns a sequence of retry attempts. The sequence has MaxAttempts elements, and calling ShouldRetry(Exception) on the last attempt will always return false. This overload assumes no deadline, and so does not require a clock.

Declaration
public static IEnumerable<RetryAttempt> CreateRetrySequence(RetrySettings settings, IScheduler scheduler, TimeSpan? initialBackoffOverride = default(TimeSpan? ))
Parameters
Type Name Description
RetrySettings settings

The retry settings to create a sequence for. Must not be null.

IScheduler scheduler

The scheduler to use for delays.

System.Nullable<System.TimeSpan> initialBackoffOverride

An override value to allow an initial backoff which is not the same as InitialBackoff. This is typically to allow an "immediate first retry".

Returns
Type Description
System.Collections.Generic.IEnumerable<RetryAttempt>

ShouldRetry(Exception)

Indicates whether the operation should be retried when the given exception has been thrown. This will return false if the exception indicates that the operation shouldn't be retried, or the maximum number of attempts has been reached, or the next backoff would exceed the overall deadline. (It is assumed that Backoff(CancellationToken) or BackoffAsync(CancellationToken) will be called immediately afterwards.)

Declaration
public bool ShouldRetry(Exception exception)
Parameters
Type Name Description
System.Exception exception

The exception thrown by the retriable operation.

Returns
Type Description
System.Boolean

true if the operation should be retried; false otherwise.

Back to top