tfresource

package
v1.60.1-0...-d0172da Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyResult = &EmptyResultError{}
View Source
var ErrFoundResource = errors.New(`found resource`)
View Source
var ErrTooManyResults = &TooManyResultsError{}

Functions

func AssertFirstValueResult

func AssertFirstValueResult[T any](a []T) (*T, error)

AssertFirstValueResult returns a pointer to the first value in the specified slice of values. Returns a `NotFound` error otherwise.

func AssertMaybeSinglePtrResult

func AssertMaybeSinglePtrResult[T any](a []*T) (option.Option[*T], error)

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

func AssertMaybeSingleValueResult[T any](a []T) (option.Option[T], error)

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

func AssertSinglePtrResult[T any](a []*T, fs ...FoundFunc[T]) (*T, error)

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

func AssertSingleValueResult[T any](a []T, fs ...FoundFunc[T]) (*T, error)

AssertSingleValueResult returns a pointer to the single value in the specified slice of values. Returns a `NotFound` error otherwise.

func NewDeadline

func NewDeadline(duration time.Duration) deadline

func NewEmptyResultError

func NewEmptyResultError(lastRequest interface{}) error

func NewTooManyResultsError

func NewTooManyResultsError(count int, lastRequest interface{}) error

func NotFound

func NotFound(err error) bool

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 RetryWhenIsA[T error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

func RetryWhenIsAErrorMessageContains

func RetryWhenIsAErrorMessageContains[T errs.ErrorWithErrorMessage](ctx context.Context, timeout time.Duration, f func() (interface{}, error), needle string) (interface{}, error)

func RetryWhenIsOneOf2

func RetryWhenIsOneOf2[T1, T2 error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

func RetryWhenIsOneOf3

func RetryWhenIsOneOf3[T1, T2, T3 error](ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

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

func SingularDataSourceFindError(resourceType string, err error) error

SingularDataSourceFindError returns a standard error message for a singular data source's non-nil resource find error.

func TimedOut

func TimedOut(err error) bool

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 FoundFunc

type FoundFunc[T any] func(*T) bool

FoundFunc is function that returns false if the specified value causes a `NotFound` error to be returned.

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

type Retryable func(error) (bool, error)

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.
}

Jump to

Keyboard shortcuts

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