Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCircuitOpen = moerr.NewInternalErrorNoCtx("retry circuit open")
ErrCircuitOpen indicates the retry circuit breaker is open.
var ErrNonRetryable = moerr.NewInternalErrorNoCtx("non-retryable error")
ErrNonRetryable indicates the operation should not be retried.
Functions ¶
This section is empty.
Types ¶
type AlwaysRetryClassifier ¶
type AlwaysRetryClassifier struct{}
AlwaysRetryClassifier retries any error.
func (AlwaysRetryClassifier) IsRetryable ¶
func (AlwaysRetryClassifier) IsRetryable(error) bool
IsRetryable implements ErrorClassifier.
type BackoffStrategy ¶
type BackoffStrategy interface {
// Next returns the wait duration before the given attempt (1-indexed).
Next(attempt int) time.Duration
}
BackoffStrategy calculates the waiting duration before the next retry attempt.
type DefaultClassifier ¶
type DefaultClassifier struct{}
DefaultClassifier recognises common transient network errors.
func (DefaultClassifier) IsRetryable ¶
func (DefaultClassifier) IsRetryable(err error) bool
IsRetryable implements ErrorClassifier.
type ErrorClassifier ¶
type ErrorClassifier interface {
// IsRetryable returns true if the error is transient and worth retrying.
IsRetryable(error) bool
}
ErrorClassifier determines whether a failure is retryable.
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// Base delay before the first retry attempt.
Base time.Duration
// Factor to multiply delays by each attempt (>1).
Factor float64
// Max caps the computed delay (optional).
Max time.Duration
// Jitter adds randomization in range [0, Jitter] (optional).
Jitter time.Duration
// contains filtered or unexported fields
}
ExponentialBackoff implements BackoffStrategy with exponential growth and optional jitter.
type MultiClassifier ¶
type MultiClassifier []ErrorClassifier
MultiClassifier chains multiple classifiers; returns true if any classifier deems the error retryable.
func (MultiClassifier) IsRetryable ¶
func (m MultiClassifier) IsRetryable(err error) bool
IsRetryable implements ErrorClassifier.
type MySQLErrorClassifier ¶
type MySQLErrorClassifier struct{}
MySQLErrorClassifier recognises transient MySQL errors that are worth retrying.
func (MySQLErrorClassifier) IsRetryable ¶
func (MySQLErrorClassifier) IsRetryable(err error) bool
IsRetryable implements ErrorClassifier.
type NeverRetryClassifier ¶
type NeverRetryClassifier struct{}
NeverRetryClassifier never retries any error.
func (NeverRetryClassifier) IsRetryable ¶
func (NeverRetryClassifier) IsRetryable(error) bool
IsRetryable implements ErrorClassifier.
type Operation ¶
type Operation func() error
Operation defines the callable that will be executed with retry semantics.
type Policy ¶
type Policy struct {
// MaxAttempts defines how many times the operation should be attempted in total.
// Must be >= 1.
MaxAttempts int
// Backoff decides how long to wait between attempts. Optional; zero value means no backoff.
Backoff BackoffStrategy
// Classifier decides whether an error warrants another attempt. Optional; defaults to never retry.
Classifier ErrorClassifier
}
Policy controls the retry behaviour for an operation.
func (Policy) Do ¶
Do executes the given Operation following the retry policy.
Behaviour:
- Executes op up to MaxAttempts times.
- If op returns nil, Do returns nil immediately.
- If op returns non-retryable error, Do returns it without further attempts.
- Between retryable failures, waits according to Backoff (if provided).
- Context cancellation aborts waiting and returns ctx.Err().