Documentation
¶
Overview ¶
Package resilience provides resilience patterns such as circuit breakers and retries.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern. It prevents the application from performing operations that are likely to fail.
func NewCircuitBreaker ¶
func NewCircuitBreaker(config *configv1.CircuitBreakerConfig) *CircuitBreaker
NewCircuitBreaker creates a new CircuitBreaker with the given configuration.
func (*CircuitBreaker) Execute ¶
func (cb *CircuitBreaker) Execute(work func() error) error
Execute runs the provided work function. If the circuit breaker is open, it returns a CircuitBreakerOpenError immediately. If the work function fails, it tracks the failure and may trip the breaker.
type CircuitBreakerOpenError ¶
type CircuitBreakerOpenError struct{}
CircuitBreakerOpenError is returned when the circuit breaker is in the Open state.
func (*CircuitBreakerOpenError) Error ¶
func (e *CircuitBreakerOpenError) Error() string
Error returns the error message for a CircuitBreakerOpenError.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates resilience features like circuit breakers and retries.
func NewManager ¶
func NewManager(config *configv1.ResilienceConfig) *Manager
NewManager creates a new Manager with the given resilience configuration.
type PermanentError ¶
type PermanentError struct {
Err error
}
PermanentError is an error that should not be retried.
func (*PermanentError) Error ¶
func (e *PermanentError) Error() string
Error returns the error message.
func (*PermanentError) Unwrap ¶
func (e *PermanentError) Unwrap() error
Unwrap returns the wrapped error.
type Retry ¶
type Retry struct {
// contains filtered or unexported fields
}
Retry implements a retry policy for failed operations.
func NewRetry ¶
func NewRetry(config *configv1.RetryConfig) *Retry
NewRetry creates a new Retry instance with the given configuration. It sets default values for base and max backoff if they are not provided.
type State ¶
type State int
State represents the current state of the circuit breaker.
const ( // StateClosed represents the state where the circuit breaker allows requests to pass through. StateClosed State = iota // StateOpen represents the state where the circuit breaker blocks requests immediately. StateOpen // StateHalfOpen represents the state where the circuit breaker allows a limited number of requests to test if the service has recovered. StateHalfOpen )