Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NetworkRequest ¶
func NetworkRequest(ctx context.Context, request func(context.Context) error, opts ...RetrierOption) error
NetworkRequest retries an operation with exponential backoff until it succeeds, max timeout is reached or context is cancelled. Default sensible values are used for total timeout, max consecutive errors and backoff. This is intended for "lightweight" network requests, like relatively fast HTTP API requests, and assumes a relatively fast network connection: response time sub 500ms. It's meant to be used for the majority of API requests we make in nodeadm, where this assumptions hold. If you are making heavy network requests, like downloading files or long polling for async operations, you should consider using a custom retrier.
Types ¶
type HandleError ¶
func NewMaxConsecutiveErrorHandler ¶
func NewMaxConsecutiveErrorHandler(maxAttempts int) HandleError
type Operation ¶
Operation is a process that can be retried. It returns a boolean indicating if the operation is done. Errors might be retried.
type Retrier ¶
type Retrier struct {
// HandleError is called after each operation retry.
// If it returns an error, the operation is not retried
// and that error is returned. This is useful for special
// error handling, for example, for non retryable errors.
// If HandleError is nil, the operation is always retried.
HandleError HandleError
// Timeout is the maximum time for the complete retry loop.
// If zero, the operation is retried indefinitely until either
// the backoff reaches its limit (if configured to do so) or
// the context is cancelled.
Timeout time.Duration
// OperationTimeout is the maximum time for a single operation.
// If zero, the operation is not timed out.
// This is controlled through the context, if the operation code
// doesn't respect the context cancellation, the operation might
// run for longer than this timeout.
OperationTimeout time.Duration
// Backoff is the backoff configuration for the retry loop.
Backoff Backoff
}
Retrier configures retries for an operation.
type RetrierOption ¶
type RetrierOption func(*Retrier)
RetrierOption is a function that modifies a Retrier. Generally only for tests.
func WithBackoffDuration ¶
func WithBackoffDuration(duration time.Duration) RetrierOption
WithBackoffDuration sets the backoff duration for the retrier.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) RetrierOption
WithTimeout sets the timeout for the retrier.