Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PollWithBackoff ¶ added in v0.16.4
PollWithBackoff calls fn immediately, then retries with exponential backoff (per cfg) until fn reports done, fn returns an error, ctx is cancelled, or a configured bound (MaxAttempts / MaxElapsed) is reached.
On ctx cancellation while waiting between attempts, PollWithBackoff returns the last result along with ctx.Err(). When a bound is reached without fn ever reporting done, it returns the last result with a nil error — callers that need retries-exhausted to be an error should check the result themselves (e.g. a not-found sentinel), mirroring how the original per-call-site loops behaved.
func WaitForStateTransition ¶
func WaitForStateTransition(ctx context.Context, resourceType, resourceID string, stateChecker StateChecker, opts ...Option) error
WaitForStateTransition waits for a resource to reach the desired state by polling its current state. The default poll interval is two seconds; pass WithPollInterval to customize it.
Types ¶
type BackoffConfig ¶ added in v0.16.4
type BackoffConfig struct {
// Initial is the delay before the second attempt. The first attempt
// always runs immediately.
Initial time.Duration
// Max caps the backoff delay after it doubles on each retry. Leave zero
// to keep the delay flat at Initial (no exponential growth).
Max time.Duration
// MaxAttempts bounds the number of attempts. Zero means unbounded (rely
// on MaxElapsed and/or ctx cancellation to stop retrying).
MaxAttempts int
// MaxElapsed bounds the total wall-clock time spent retrying, measured
// from the first attempt. Zero means unbounded (rely on MaxAttempts
// and/or ctx cancellation to stop retrying).
MaxElapsed time.Duration
}
BackoffConfig bounds the retry policy used by PollWithBackoff. It generalizes the wall-clock-bound, attempt-count-bound, and flat-delay policies that call sites previously hand-rolled independently.
type Option ¶ added in v0.16.1
type Option func(*waitConfig)
Option customizes WaitForStateTransition behavior.
func WithPollInterval ¶ added in v0.16.1
WithPollInterval overrides the default polling interval. Useful for long-running resources (e.g. connector sync jobs) where a slower cadence is more appropriate than the default snappy 2-second tick.
type PollFunc ¶ added in v0.16.4
PollFunc performs one poll attempt, 1-indexed by attempt. It returns the current result, whether polling should stop (done), and any error. A non-nil error stops polling immediately, same as done=true.
type StateChecker ¶
StateChecker is a function that checks if a resource is in the desired state. It should return true if the resource is in the desired state, false otherwise, and any error that occurred during the check.