Documentation
¶
Overview ¶
Package retrier provides a small, value-aware retry loop for waiting on asynchronous state transitions (e.g. cluster startup, workspace creation) and for retrying transient errors that the Databricks SDK does not absorb itself. Retriers are constructed fresh per Run so independent invocations have independent backoff state and can run concurrently.
Index ¶
- func RetryIf[V any](bp BackoffPolicy, isRetriable func(V, error) bool) func() Retrier[V]
- func RetryIfErr(bp BackoffPolicy, isRetriable func(error) bool) func() RetrierErr
- func Run[V any](ctx context.Context, newR func() Retrier[V], ...) (V, error)
- func RunErr(ctx context.Context, newR func() RetrierErr, fn func(context.Context) error) error
- type BackoffPolicy
- type Retrier
- type RetrierErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RetryIf ¶
func RetryIf[V any](bp BackoffPolicy, isRetriable func(V, error) bool) func() Retrier[V]
RetryIf returns a retrier factory suitable for passing to Run. The constructed retrier calls isRetriable after every attempt and, when it returns true, sleeps for the duration produced by a fresh copy of bp before the next attempt. bp is captured by value, so independent Run invocations get independent backoff state and can run concurrently.
func RetryIfErr ¶
func RetryIfErr(bp BackoffPolicy, isRetriable func(error) bool) func() RetrierErr
RetryIfErr is the error-only analog of RetryIf, suitable for passing to RunErr. The isRetriable predicate sees only the error.
func Run ¶
func Run[V any](ctx context.Context, newR func() Retrier[V], fn func(context.Context) (V, error)) (V, error)
Run executes fn, retrying according to the retrier constructed by newR. newR is invoked once per Run call so each invocation has its own independent retrier state; this makes Run safe to use from multiple goroutines with the same newR. If newR is nil, or if it returns nil, Run performs exactly one attempt with no retry logic. It returns the value and error of the final attempt.
Run honours context cancellation between attempts and during sleeps; if ctx completes, Run returns the last attempt's value and ctx.Err().
Types ¶
type BackoffPolicy ¶
type BackoffPolicy struct {
// Initial delay before the first retry; defaults to 10 seconds.
Initial time.Duration
// Maximum delay between retries; defaults to 5 minutes.
Maximum time.Duration
// Factor by which the delay grows after each retry. Must be >= 1;
// defaults to 2 if zero or negative.
Factor float64
// contains filtered or unexported fields
}
BackoffPolicy implements a deterministic exponential backoff. The retry delay starts at Initial and grows by Factor at every step, capped at Maximum. There is no jitter: the Databricks SDK already retries transient errors on its own, and state-polling waiters in this package do not need cross-client decorrelation.
BackoffPolicies are stateful and cannot be reset. Construct a new one per Run invocation rather than reusing.
func (*BackoffPolicy) Next ¶
func (bp *BackoffPolicy) Next() time.Duration
type Retrier ¶
Retrier decides whether to retry an operation based on the outcome of the last attempt. IsRetriable is called after every attempt with the value and error produced by that attempt. It returns the delay to wait before the next attempt and whether to retry at all.
Passing both value and error lets callers express either of the two dominant retry policies in this codebase:
- error-driven: retry transient errors (e.g. 504, timeout); halt on terminal errors; halt on success.
- state-driven: retry while the value is in a non-terminal state (e.g. a cluster in PENDING); halt when the value reaches a terminal state; halt on any error.
State-driven polling is the majority of retry sites in this provider, so the value is always passed in. Error-driven retriers ignore it.
type RetrierErr ¶
type RetrierErr = Retrier[struct{}]
RetrierErr is the error-only specialisation of Retrier, for retry policies that do not inspect the operation's result value (e.g. retrying on transient errors, polling until a resource is deleted).