Documentation ¶
Index ¶
- Variables
- func AssertFirstValueResult[T any](a []T) (*T, error)
- func AssertMaybeSinglePtrResult[T any](a []*T) (option.Option[*T], error)
- func AssertMaybeSingleValueResult[T any](a []T) (option.Option[T], error)
- func AssertSinglePtrResult[T any](a []*T, fs ...foundFunc[T]) (*T, error)
- func AssertSingleValueResult[T any](a []T, fs ...foundFunc[T]) (*T, error)
- func NewDeadline(duration time.Duration) deadline
- func NewEmptyResultError(lastRequest interface{}) error
- func NewTooManyResultsError(count int, lastRequest interface{}) error
- func NotFound(err error) bool
- func Retry(ctx context.Context, timeout time.Duration, f retry.RetryFunc, ...) error
- func RetryGWhen[T any](ctx context.Context, timeout time.Duration, f func() (T, error), ...) (T, error)
- func RetryGWhenMessageContains[T any](ctx context.Context, timeout time.Duration, f func() (T, error), ...) (T, error)
- func RetryUntilEqual[T comparable](ctx context.Context, timeout time.Duration, t T, f func() (T, error)) (T, error)
- func RetryUntilNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
- func RetryWhen(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenAWSErrCodeContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenAWSErrMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenHTTPStatusCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenIsA[T error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
- func RetryWhenIsAErrorMessageContains[T errs.ErrorWithErrorMessage](ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenIsOneOf2[T1, T2 error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
- func RetryWhenIsOneOf3[T1, T2, T3 error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
- func RetryWhenMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenNewResourceNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error), ...) (interface{}, error)
- func RetryWhenNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
- func SetLastError(err, lastErr error)
- func SingularDataSourceFindError(resourceType string, err error) error
- func TimedOut(err error) bool
- func WaitUntil(ctx context.Context, timeout time.Duration, f func() (bool, error), ...) error
- type EmptyResultError
- type Options
- type OptionsFunc
- func WithContinuousTargetOccurence(continuousTargetOccurence int) OptionsFunc
- func WithDelay(delay time.Duration) OptionsFunc
- func WithDelayRand(delayRand time.Duration) OptionsFunc
- func WithMinPollInterval(minPollInterval time.Duration) OptionsFunc
- func WithNotFoundChecks(notFoundChecks int) OptionsFunc
- func WithPollInterval(pollInterval time.Duration) OptionsFunc
- type Retryable
- type TooManyResultsError
- type WaitOpts
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyResult = &EmptyResultError{}
var ErrFoundResource = errors.New(`found resource`)
var ErrTooManyResults = &TooManyResultsError{}
Functions ¶
func AssertFirstValueResult ¶
AssertFirstValueResult returns a pointer to the first value in the specified slice of values. Returns a `NotFound` error otherwise.
func AssertMaybeSinglePtrResult ¶
AssertMaybeSinglePtrResult returns the single non-nil pointer value in the specified slice, or `None` if the slice is empty. Returns a `NotFound` error otherwise.
func AssertMaybeSingleValueResult ¶
AssertMaybeSingleValueResult returns the single non-nil value in the specified slice, or `None` if the slice is empty. Returns a `NotFound` error otherwise.
func AssertSinglePtrResult ¶
AssertSinglePtrResult returns the single non-nil pointer value in the specified slice. Returns a `NotFound` error otherwise. If any of the specified functions return false for the value, a `NotFound` error is returned.
func AssertSingleValueResult ¶
AssertSingleValueResult returns a pointer to the single value in the specified slice of values. Returns a `NotFound` error otherwise.
func NewDeadline ¶
func NewEmptyResultError ¶
func NewEmptyResultError(lastRequest interface{}) error
func NewTooManyResultsError ¶
func NotFound ¶
NotFound returns true if the error represents a "resource not found" condition. Specifically, NotFound returns true if the error or a wrapped error is of type retry.NotFoundError.
func Retry ¶
func Retry(ctx context.Context, timeout time.Duration, f retry.RetryFunc, optFns ...OptionsFunc) error
Retry allows configuration of StateChangeConf's various time arguments. This is especially useful for AWS services that are prone to throttling, such as Route53, where the default durations cause problems.
func RetryGWhen ¶
func RetryGWhen[T any](ctx context.Context, timeout time.Duration, f func() (T, error), retryable Retryable) (T, error)
RetryGWhen is the generic version of RetryWhen which obviates the need for a type assertion after the call. It retries the function `f` when the error it returns satisfies `retryable`. `f` is retried until `timeout` expires.
func RetryGWhenMessageContains ¶
func RetryGWhenMessageContains[T any](ctx context.Context, timeout time.Duration, f func() (T, error), codes []string, messages []string) (T, error)
RetryGWhenMessageContains retries the specified function when it returns an error containing any of the specified messages.
func RetryUntilEqual ¶
func RetryUntilEqual[T comparable](ctx context.Context, timeout time.Duration, t T, f func() (T, error)) (T, error)
RetryUntilEqual retries the specified function until it returns a value equal to `t`.
func RetryUntilNotFound ¶
func RetryUntilNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
RetryUntilNotFound retries the specified function until it returns a retry.NotFoundError.
func RetryWhen ¶
func RetryWhen(ctx context.Context, timeout time.Duration, f func() (interface{}, error), retryable Retryable) (interface{}, error)
RetryWhen retries the function `f` when the error it returns satisfies `retryable`. `f` is retried until `timeout` expires.
func RetryWhenAWSErrCodeContains ¶
func RetryWhenAWSErrCodeContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code string) (interface{}, error)
RetryWhenAWSErrCodeContains retries the specified function when it returns an AWS error containing the specified code.
func RetryWhenAWSErrCodeEquals ¶
func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error)
RetryWhenAWSErrCodeEquals retries the specified function when it returns one of the specified AWS error codes.
func RetryWhenAWSErrMessageContains ¶
func RetryWhenAWSErrMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code, message string) (interface{}, error)
RetryWhenAWSErrMessageContains retries the specified function when it returns an AWS error containing the specified message.
func RetryWhenHTTPStatusCodeEquals ¶
func RetryWhenHTTPStatusCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), statusCodes ...int) (interface{}, error)
RetryWhenHTTPStatusCodeEquals retries the specified function when it returns one of the specified HTTP status codes.
func RetryWhenIsA ¶
func RetryWhenIsOneOf2 ¶
func RetryWhenIsOneOf3 ¶
func RetryWhenMessageContains ¶
func RetryWhenMessageContains(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes []string, messages []string) (interface{}, error)
RetryWhenMessageContains retries the specified function when it returns an error containing any of the specified messages.
func RetryWhenNewResourceNotFound ¶
func RetryWhenNewResourceNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error), isNewResource bool) (interface{}, error)
RetryWhenNewResourceNotFound retries the specified function when it returns a retry.NotFoundError and `isNewResource` is true.
func RetryWhenNotFound ¶
func RetryWhenNotFound(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)
RetryWhenNotFound retries the specified function when it returns a retry.NotFoundError.
func SetLastError ¶
func SetLastError(err, lastErr error)
SetLastError sets the LastError field on the error if supported. If lastErr is nil it is ignored.
func SingularDataSourceFindError ¶
SingularDataSourceFindError returns a standard error message for a singular data source's non-nil resource find error.
func TimedOut ¶
TimedOut returns true if the error represents a "wait timed out" condition. Specifically, TimedOut returns true if the error matches all these conditions:
- err is of type retry.TimeoutError
- TimeoutError.LastError is nil
func WaitUntil ¶
func WaitUntil(ctx context.Context, timeout time.Duration, f func() (bool, error), opts WaitOpts) error
WaitUntil waits for the function `f` to return `true`. If `f` returns an error, return immediately with that error. If `timeout` is exceeded before `f` returns `true`, return an error. Waits between calls to `f` using exponential backoff, except when waiting for the target state to reoccur.
Types ¶
type EmptyResultError ¶
type EmptyResultError struct {
LastRequest interface{}
}
func (*EmptyResultError) As ¶
func (e *EmptyResultError) As(target interface{}) bool
func (*EmptyResultError) Error ¶
func (e *EmptyResultError) Error() string
func (*EmptyResultError) Is ¶
func (e *EmptyResultError) Is(err error) bool
type Options ¶
type Options struct { Delay time.Duration // Wait this time before starting checks MinPollInterval time.Duration // Smallest time to wait before refreshes (MinTimeout in retry.StateChangeConf) PollInterval time.Duration // Override MinPollInterval/backoff and only poll this often NotFoundChecks int // Number of times to allow not found (nil result from Refresh) ContinuousTargetOccurence int // Number of times the Target state has to occur continuously }
func (Options) Apply ¶
func (o Options) Apply(c *retry.StateChangeConf)
type OptionsFunc ¶
type OptionsFunc func(*Options)
func WithContinuousTargetOccurence ¶
func WithContinuousTargetOccurence(continuousTargetOccurence int) OptionsFunc
func WithDelay ¶
func WithDelay(delay time.Duration) OptionsFunc
func WithDelayRand ¶
func WithDelayRand(delayRand time.Duration) OptionsFunc
WithDelayRand sets the delay to a value between 0s and the passed duration
func WithMinPollInterval ¶
func WithMinPollInterval(minPollInterval time.Duration) OptionsFunc
func WithNotFoundChecks ¶
func WithNotFoundChecks(notFoundChecks int) OptionsFunc
func WithPollInterval ¶
func WithPollInterval(pollInterval time.Duration) OptionsFunc
type Retryable ¶
Retryable is a function that is used to decide if a function's error is retryable or not. The error argument can be `nil`. If the error is retryable, returns a bool value of `true` and an error (not necessarily the error passed as the argument). If the error is not retryable, returns a bool value of `false` and either no error (success state) or an error (not necessarily the error passed as the argument).
type TooManyResultsError ¶
type TooManyResultsError struct { Count int LastRequest interface{} }
func (*TooManyResultsError) As ¶
func (e *TooManyResultsError) As(target interface{}) bool
func (*TooManyResultsError) Error ¶
func (e *TooManyResultsError) Error() string
func (*TooManyResultsError) Is ¶
func (e *TooManyResultsError) Is(err error) bool
type WaitOpts ¶
type WaitOpts struct { ContinuousTargetOccurence int // Number of times the target state has to occur continuously. Delay time.Duration // Wait this time before starting checks. MinTimeout time.Duration // Smallest time to wait before refreshes. PollInterval time.Duration // Override MinTimeout/backoff and only poll this often. }