public sealed 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.
Namespace
Google.Api.Gax.GrpcAssembly
Google.Api.Gax.Grpc.dll
Properties
AttemptNumber
public int AttemptNumber { get; }
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.
Property Value | |
---|---|
Type | Description |
Int32 |
JitteredBackoff
public TimeSpan JitteredBackoff { get; }
The time that will be used to sleep or delay in Backoff(CancellationToken) and BackoffAsync(CancellationToken). This has already had jitter applied to it.
Property Value | |
---|---|
Type | Description |
TimeSpan |
Methods
Backoff(CancellationToken)
public void Backoff(CancellationToken cancellationToken)
Synchronously sleeps for a period of JitteredBackoff.
Parameter | |
---|---|
Name | Description |
cancellationToken | CancellationToken The cancellation token to apply to the sleep operation. |
BackoffAsync(CancellationToken)
public Task BackoffAsync(CancellationToken cancellationToken)
Asynchronously delays for a period of JitteredBackoff.
Parameter | |
---|---|
Name | Description |
cancellationToken | CancellationToken The cancellation token to apply to the delay operation. |
Returns | |
---|---|
Type | Description |
Task |
CreateRetrySequence(RetrySettings, IScheduler, Nullable<DateTime>, IClock, Nullable<TimeSpan>)
public static IEnumerable<RetryAttempt> CreateRetrySequence(RetrySettings settings, IScheduler scheduler, DateTime? deadline, IClock clock, TimeSpan? initialBackoffOverride = null)
Returns a sequence of retry attempts. The sequence has MaxAttempts elements, and calling ShouldRetry(Exception) on the last attempt will always return false.
Parameters | |
---|---|
Name | Description |
settings | RetrySettings The retry settings to create a sequence for. Must not be null. |
scheduler | IScheduler The scheduler to use for delays. |
deadline | Nullable<DateTime> The overall deadline for the operation. |
clock | IClock The clock to use to compare the current time with the deadline. |
initialBackoffOverride | Nullable<TimeSpan> 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 |
IEnumerable<RetryAttempt> |
CreateRetrySequence(RetrySettings, IScheduler, Nullable<TimeSpan>)
public static IEnumerable<RetryAttempt> CreateRetrySequence(RetrySettings settings, IScheduler scheduler, TimeSpan? initialBackoffOverride = null)
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.
Parameters | |
---|---|
Name | Description |
settings | RetrySettings The retry settings to create a sequence for. Must not be null. |
scheduler | IScheduler The scheduler to use for delays. |
initialBackoffOverride | Nullable<TimeSpan> 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 |
IEnumerable<RetryAttempt> |
ShouldRetry(Exception)
public bool ShouldRetry(Exception 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.)
Parameter | |
---|---|
Name | Description |
exception | Exception The exception thrown by the retriable operation. |
Returns | |
---|---|
Type | Description |
Boolean |
|