tfresource

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MPL-2.0 Imports: 10 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 AssertSinglePtrResult

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

func AssertSingleValueResult

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

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

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