Documentation
¶
Overview ¶
Package retry provides exponential backoff with jitter for paper-board service gRPC call sites. It is the inner tier of the two-layer retry strategy (D9.4): sdk/retry handles transient blips at the call site; the outbox publish retry (sdk/outbox) is the outer tier.
Usage ¶
ctx = retry.WithTarget(ctx, "vaults.GetCredential")
err := retry.Do(ctx, retry.DefaultPolicy, func(ctx context.Context) error {
resp, err = vaultsClient.GetCredential(ctx, req)
return err
})
Retry decision ¶
Per attempt:
- IsRetryable(err) → schedule retry (subject to MaxAttempts)
- IsPermanent(err) → return immediately, no retry
- ClassificationUnknown → treated as Permanent (fail-loud, no silent retries)
Jitter ¶
Mandatory ±20% jitter (D9.4) prevents thundering herd when many services retry against the same downstream.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultPolicy = Policy{ MaxAttempts: 3, BaseDelay: 200 * time.Millisecond, MaxDelay: 2 * time.Second, Factor: 2.0, Jitter: 0.2, }
DefaultPolicy is the D9.4 inner-tier configuration.
Functions ¶
Types ¶
type Policy ¶
type Policy struct {
// MaxAttempts is the total number of attempts (first + retries).
// Default: 3 (D9.4 inner tier).
MaxAttempts int
// BaseDelay is the delay before the second attempt.
// Default: 200ms.
BaseDelay time.Duration
// MaxDelay caps the computed delay.
// Default: 2s.
MaxDelay time.Duration
// Factor is the exponential growth multiplier.
// Default: 2.0.
Factor float64
// Jitter is the ±fraction applied to each delay.
// Default: 0.2 (±20%, mandatory per D9.4).
Jitter float64
// Logger emits one INFO line per attempt with retry context.
// Uses slog.Default() if nil.
Logger *slog.Logger
}
Policy controls retry behaviour.
Click to show internal directories.
Click to hide internal directories.