Documentation ¶
Index ¶
- Variables
- func IgnoreErrors(errorsToExclude []error) func(error) bool
- func Retry(ctx context.Context, operation Operation, policy RetryPolicy, ...) error
- type Clock
- type ConcurrentRetrier
- func (c *ConcurrentRetrier) Failed(includeSecondaryRetryPolicy bool)
- func (c *ConcurrentRetrier) GetElapsedTime() time.Duration
- func (c *ConcurrentRetrier) SetSecondaryRetryPolicy(retryPolicy RetryPolicy)
- func (c *ConcurrentRetrier) Succeeded()
- func (c *ConcurrentRetrier) Throttle(doneCh <-chan struct{})
- type ExponentialRetryPolicy
- func (p *ExponentialRetryPolicy) ComputeNextDelay(elapsedTime time.Duration, attempt int) time.Duration
- func (p *ExponentialRetryPolicy) GrpcRetryConfig() *retry.GrpcRetryConfig
- func (p *ExponentialRetryPolicy) SetBackoffCoefficient(backoffCoefficient float64)
- func (p *ExponentialRetryPolicy) SetExpirationInterval(expirationInterval time.Duration)
- func (p *ExponentialRetryPolicy) SetInitialInterval(initialInterval time.Duration)
- func (p *ExponentialRetryPolicy) SetMaximumAttempts(maximumAttempts int)
- func (p *ExponentialRetryPolicy) SetMaximumInterval(maximumInterval time.Duration)
- type IsRetryable
- type Operation
- type Retrier
- type RetryPolicy
Constants ¶
This section is empty.
Variables ¶
var SystemClock = systemClock{}
SystemClock implements Clock interface that uses time.Now().
Functions ¶
func IgnoreErrors ¶
IgnoreErrors can be used as IsRetryable handler for Retry function to exclude certain errors from the retry list
func Retry ¶
func Retry(ctx context.Context, operation Operation, policy RetryPolicy, isRetryable IsRetryable) error
Retry function can be used to wrap any call with retry logic using the passed in policy
Types ¶
type Clock ¶
Clock used by ExponentialRetryPolicy implementation to get the current time. Mainly used for unit testing
type ConcurrentRetrier ¶
ConcurrentRetrier is used for client-side throttling. It determines whether to throttle outgoing traffic in case downstream backend server rejects requests due to out-of-quota or server busy errors.
func NewConcurrentRetrier ¶
func NewConcurrentRetrier(retryPolicy RetryPolicy) *ConcurrentRetrier
NewConcurrentRetrier returns an instance of concurrent backoff retrier.
func (*ConcurrentRetrier) Failed ¶
func (c *ConcurrentRetrier) Failed(includeSecondaryRetryPolicy bool)
Failed marks client request failed because backend is busy. If includeSecondaryRetryPolicy is true, see SetSecondaryRetryPolicy for effects.
func (*ConcurrentRetrier) GetElapsedTime ¶ added in v1.21.1
func (c *ConcurrentRetrier) GetElapsedTime() time.Duration
GetElapsedTime gets the amount of time since that last ConcurrentRetrier.Succeeded call
func (*ConcurrentRetrier) SetSecondaryRetryPolicy ¶ added in v1.18.0
func (c *ConcurrentRetrier) SetSecondaryRetryPolicy(retryPolicy RetryPolicy)
SetSecondaryRetryPolicy sets a secondary retry policy that, if Failed is called with true, will trigger the secondary retry policy in addition to the primary and will use the result of the secondary if longer than the primary.
func (*ConcurrentRetrier) Succeeded ¶
func (c *ConcurrentRetrier) Succeeded()
Succeeded marks client request succeeded.
func (*ConcurrentRetrier) Throttle ¶
func (c *ConcurrentRetrier) Throttle(doneCh <-chan struct{})
Throttle Sleep if there were failures since the last success call. The provided done channel provides a way to exit early.
type ExponentialRetryPolicy ¶
type ExponentialRetryPolicy struct {
// contains filtered or unexported fields
}
ExponentialRetryPolicy provides the implementation for retry policy using a coefficient to compute the next delay. Formula used to compute the next delay is: initialInterval * math.Pow(backoffCoefficient, currentAttempt)
func NewExponentialRetryPolicy ¶
func NewExponentialRetryPolicy(initialInterval time.Duration) *ExponentialRetryPolicy
NewExponentialRetryPolicy returns an instance of ExponentialRetryPolicy using the provided initialInterval
func (*ExponentialRetryPolicy) ComputeNextDelay ¶
func (p *ExponentialRetryPolicy) ComputeNextDelay(elapsedTime time.Duration, attempt int) time.Duration
ComputeNextDelay returns the next delay interval. This is used by Retrier to delay calling the operation again
func (*ExponentialRetryPolicy) GrpcRetryConfig ¶ added in v1.7.0
func (p *ExponentialRetryPolicy) GrpcRetryConfig() *retry.GrpcRetryConfig
GrpcRetryConfig converts retry policy into retry config.
func (*ExponentialRetryPolicy) SetBackoffCoefficient ¶
func (p *ExponentialRetryPolicy) SetBackoffCoefficient(backoffCoefficient float64)
SetBackoffCoefficient sets the coefficient used by ExponentialRetryPolicy to compute next delay for each retry All retries are computed using the following formula: initialInterval * math.Pow(backoffCoefficient, currentAttempt)
func (*ExponentialRetryPolicy) SetExpirationInterval ¶
func (p *ExponentialRetryPolicy) SetExpirationInterval(expirationInterval time.Duration)
SetExpirationInterval sets the absolute expiration interval for all retries
func (*ExponentialRetryPolicy) SetInitialInterval ¶
func (p *ExponentialRetryPolicy) SetInitialInterval(initialInterval time.Duration)
SetInitialInterval sets the initial interval used by ExponentialRetryPolicy for the very first retry All later retries are computed using the following formula: initialInterval * math.Pow(backoffCoefficient, currentAttempt)
func (*ExponentialRetryPolicy) SetMaximumAttempts ¶
func (p *ExponentialRetryPolicy) SetMaximumAttempts(maximumAttempts int)
SetMaximumAttempts sets the maximum number of retry attempts
func (*ExponentialRetryPolicy) SetMaximumInterval ¶
func (p *ExponentialRetryPolicy) SetMaximumInterval(maximumInterval time.Duration)
SetMaximumInterval sets the maximum interval for each retry
type IsRetryable ¶
IsRetryable handler can be used to exclude certain errors during retry
type Retrier ¶
Retrier manages the state of retry operation
func NewRetrier ¶
func NewRetrier(policy RetryPolicy, clock Clock) Retrier
NewRetrier is used for creating a new instance of Retrier
type RetryPolicy ¶
type RetryPolicy interface { ComputeNextDelay(elapsedTime time.Duration, attempt int) time.Duration GrpcRetryConfig() *retry.GrpcRetryConfig }
RetryPolicy is the API which needs to be implemented by various retry policy implementations