retry

package
v0.0.0-...-476b611 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRetry = Retry{MaxWait: 64, MaxRetries: 8}
View Source
var ErrOutOfRetries = fmt.Errorf("tried too many times")

Functions

func HTTPErrNotFound

func HTTPErrNotFound(err error) bool

func RetryFunc

func RetryFunc(ctx context.Context, f func(ctx context.Context) error, shouldRetry func(error) bool, c Retry) error

func RetryQuery

func RetryQuery(ctx context.Context, c *graphql.Client, query any, vars map[string]any) error

func RetryQueryConfig

func RetryQueryConfig(ctx context.Context, c *graphql.Client, query any, vars map[string]any, r Retry) error

func RetryRequest

func RetryRequest(c *http.Client, req *http.Request) (*http.Response, error)

func RetryRequestWithRetry

func RetryRequestWithRetry(c *http.Client, req *http.Request, r Retry) (*http.Response, error)

func WaitTime

func WaitTime(minWait, maxWait int, tryIteration int) time.Duration

Types

type Limiter

type Limiter interface {
	ForKey(context.Context, string) (bool, time.Duration, error)
}

type Retry

type Retry struct {
	MinWait    int // Min amount of time to sleep per iteration in seconds
	MaxWait    int // Max amount of time to sleep per iteration in seconds
	MaxRetries int // Number of times to retry
}

Retry is a configuration for retrying requests

type Retryer

type Retryer struct {
	// contains filtered or unexported fields
}

Retryer protects against rate limits by requiring requests to be sent through it. Retryer checks its underlying rate limiter before sending the request, and if the rate limit is exceeded, it will wait before retrying the request. If the request does get rate limited by the external service even after checking the rate limiter, then Retryer will automatically re-enqueue the request with exponential backoff. Retryer will handle requests in the same order they are received. For retries, the request will be re-enqueued and won't be retried until it is popped off the queue again.

func New

func New(l Limiter, c *http.Client) (*Retryer, func())

func (*Retryer) Do

func (r *Retryer) Do(req *http.Request) (*http.Response, error)

func (*Retryer) DoRetry

func (r *Retryer) DoRetry(req *http.Request, c Retry) (*http.Response, error)

Jump to

Keyboard shortcuts

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