tfresource

package
v0.0.0-...-c441d59 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyResult = &EmptyResultError{}
View Source
var ErrTooManyResults = &TooManyResultsError{}

Functions

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 resource.NotFoundError.

func RetryConfigContext

func RetryConfigContext(ctx context.Context, delay time.Duration, delayRand time.Duration, minTimeout time.Duration, pollInterval time.Duration, timeout time.Duration, f resource.RetryFunc) error

RetryConfigContext 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. To not use a StateChangeConf argument and revert to the default, pass in a zero value (i.e., 0*time.Second).

func RetryUntilNotFound

func RetryUntilNotFound(timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

RetryUntilNotFound retries the specified function until it returns a resource.NotFoundError.

func RetryUntilNotFoundContext

func RetryUntilNotFoundContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

RetryUntilNotFoundContext retries the specified function until it returns a resource.NotFoundError.

func RetryWhen

func RetryWhen(timeout time.Duration, f func() (interface{}, error), retryable Retryable) (interface{}, error)

RetryWhen retries the function `f` when the error it returns satisfies `predicate`. `f` is retried until `timeout` expires.

func RetryWhenAWSErrCodeEquals

func RetryWhenAWSErrCodeEquals(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 code.

func RetryWhenAWSErrCodeEqualsContext

func RetryWhenAWSErrCodeEqualsContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error)

RetryWhenAWSErrCodeEqualsContext retries the specified function when it returns one of the specified AWS error code.

func RetryWhenAWSErrMessageContains

func RetryWhenAWSErrMessageContains(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 RetryWhenAWSErrMessageContainsContext

func RetryWhenAWSErrMessageContainsContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error), code, message string) (interface{}, error)

RetryWhenAWSErrMessageContainsContext retries the specified function when it returns an AWS error containing the specified message.

func RetryWhenContext

func RetryWhenContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error), retryable Retryable) (interface{}, error)

RetryWhenContext retries the function `f` when the error it returns satisfies `predicate`. `f` is retried until `timeout` expires.

func RetryWhenNewResourceNotFound

func RetryWhenNewResourceNotFound(timeout time.Duration, f func() (interface{}, error), isNewResource bool) (interface{}, error)

RetryWhenNewResourceNotFound retries the specified function when it returns a resource.NotFoundError and `isNewResource` is true.

func RetryWhenNewResourceNotFoundContext

func RetryWhenNewResourceNotFoundContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error), isNewResource bool) (interface{}, error)

RetryWhenNewResourceNotFoundContext retries the specified function when it returns a resource.NotFoundError and `isNewResource` is true.

func RetryWhenNotFound

func RetryWhenNotFound(timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

RetryWhenNotFound retries the specified function when it returns a resource.NotFoundError.

func RetryWhenNotFoundContext

func RetryWhenNotFoundContext(ctx context.Context, timeout time.Duration, f func() (interface{}, error)) (interface{}, error)

RetryWhenNotFoundContext retries the specified function when it returns a resource.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 resource.TimeoutError
  • TimeoutError.LastError is nil

func WaitUntil

func WaitUntil(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.

func WaitUntilContext

func WaitUntilContext(ctx context.Context, timeout time.Duration, f func() (bool, error), opts WaitOpts) error

WaitUntilContext 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 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