Documentation
¶
Overview ¶
Package policy provides shared retry and failure-classification primitives for evt-backed handlers.
Index ¶
- Constants
- func AllTransient(errs []error) bool
- func Execute(ctx context.Context, cfg Config, op func() error, hooks Hooks) error
- func ExecuteWithRetry(ctx context.Context, store evt.Store, factory evt.EntityFactory, ...) (evt.Entity, error)
- func ExponentialJitterDelay(baseDelay, maxDelay time.Duration, attempt int, ...) time.Duration
- func IsClassifiedErr(err error) bool
- func IsPermanent(err error) bool
- func IsTransient(err error) bool
- func SleepWithContext(ctx context.Context, delay time.Duration) error
- type Attempt
- type Class
- type ClassifiedError
- type Classifier
- type Config
- type Hooks
Constants ¶
const ( // DefaultMaxAttempts is the default number of retry attempts for commit paths. DefaultMaxAttempts = 5 // DefaultBaseDelay is the default base delay between retries. DefaultBaseDelay = 100 * time.Millisecond // DefaultMaxDelay is the default maximum delay between retries. DefaultMaxDelay = 2 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func AllTransient ¶
AllTransient reports whether every provided error is transient.
func ExecuteWithRetry ¶
func ExecuteWithRetry( ctx context.Context, store evt.Store, factory evt.EntityFactory, entityID evt.EntityID, command evt.Command, metadata evt.Metadata, cfg Config, hooks Hooks, ) (evt.Entity, error)
ExecuteWithRetry runs Store.Execute inside a bounded retry loop. On transient commit failures the entity is reloaded from scratch via the factory before the next attempt. Errors returned on give-up are wrapped in ClassifiedError.
func ExponentialJitterDelay ¶
func ExponentialJitterDelay(baseDelay, maxDelay time.Duration, attempt int, jitter func(time.Duration) time.Duration) time.Duration
ExponentialJitterDelay returns bounded exponential backoff with jitter in [base/2, base].
func IsClassifiedErr ¶
IsClassifiedErr returns true when err is a ClassifiedError.
func IsPermanent ¶
IsPermanent reports whether an error should be dropped to DLQ without retries.
func IsTransient ¶
IsTransient reports whether an error should be retried.
Types ¶
type ClassifiedError ¶
ClassifiedError wraps an error with its failure class so callers can inspect the classification without re-calling Classify.
func WrapClassified ¶
func WrapClassified(err error) *ClassifiedError
WrapClassified classifies err and wraps it in a ClassifiedError.
func (*ClassifiedError) Error ¶
func (e *ClassifiedError) Error() string
Error returns the underlying error message.
func (*ClassifiedError) Unwrap ¶
func (e *ClassifiedError) Unwrap() error
Unwrap returns the underlying error.
type Classifier ¶
Classifier maps an error into a retry/failure class.
type Config ¶
type Config struct {
MaxAttempts int
BaseDelay time.Duration
MaxDelay time.Duration
Jitter func(time.Duration) time.Duration
Sleep func(context.Context, time.Duration) error
IsRetryable func(error) bool
Classify Classifier
}
Config controls retry behavior for optimistic-concurrency commit paths.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for optimistic-concurrency retry on evt Store commit paths.