retry

package
v0.0.0-...-417428f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TODO(seukyaso): Consider adding some non-zero default retry options
	DefaultRetriableCodes = []codes.Code{codes.ResourceExhausted, codes.Unavailable}
)

Functions

func Interceptor

func Interceptor(callOpts ...grpc.CallOption) grpc.UnaryClientInterceptor

Interceptor returns retry interceptor, that can be parametrized by specific call options. Without any option, it uses default options, that basically retries nothing. Default retry quantity is 0, backoff function is nil, retry codes are DefaultRetriableCodes, AttemptHeader is false, and perCallTimeout is 0.

func WithAttemptHeader

func WithAttemptHeader(enable bool) grpc.CallOption

WithAttemptHeader adds retry attempt number to context outgoing metadata, with key "x-retry-attempt".

func WithBackoff

func WithBackoff(f BackoffFunc) grpc.CallOption

WithBackoff sets up interceptor with custom defined backoff function

func WithCodes

func WithCodes(codes ...codes.Code) grpc.CallOption

WithCodes overrides the whole retriable codes list.

func WithDefaultInterceptor

func WithDefaultInterceptor() grpc.DialOption

WithDefaultInterceptor returns interceptor that DOESN'T retry anything. Its possible to change its behaviour with call options.

func WithMax

func WithMax(maxRetryCount int) grpc.CallOption

WithMax option sets quantity of retry attempts. It handles negative maxRetryCount as INFINITE retries.

func WithPerCallTimeout

func WithPerCallTimeout(to time.Duration) grpc.CallOption

WithPerCallTimeout adds timeout for retry calls.

Types

type BackoffFunc

type BackoffFunc func(attempt int) time.Duration

func BackoffExponentialWithJitter

func BackoffExponentialWithJitter(base time.Duration, cap time.Duration) BackoffFunc

func BackoffLinearWithJitter

func BackoffLinearWithJitter(waitBetween time.Duration, jitterFraction float64) BackoffFunc

func DefaultBackoff

func DefaultBackoff() BackoffFunc

DefaultBackoff uses exponential backoff with jitter, with base = 50ms, and maximum timeout = 1 minute.

func DefaultExponentialJitterBackoff

func DefaultExponentialJitterBackoff() BackoffFunc

WithDefaultExponentialJitterBackoff same as WithDefaultBackoff

func DefaultLinearJitterBackoff

func DefaultLinearJitterBackoff() BackoffFunc

DefaultLinearJitterBackoff uses linear backoff with base = 50ms, and jitter = +-10%

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL