Documentation
¶
Overview ¶
Package circuitbreaker implements the circuit breaker pattern to prevent cascading failures when external services (LLM, gRPC, SQLite) degrade.
States: Closed (normal) → Open (failing) → HalfOpen (testing) → Closed
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOpen = errors.New("circuit breaker is open")
ErrOpen is returned when the circuit breaker is open and requests are rejected.
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker implements the circuit breaker pattern with thread-safe state transitions.
func (*Breaker) Allow ¶
Allow checks if a request should be allowed through. Returns ErrOpen if the circuit is open and recovery timeout hasn't elapsed.
func (*Breaker) RecordFailure ¶
func (b *Breaker) RecordFailure()
RecordFailure records a failed operation.
func (*Breaker) RecordSuccess ¶
func (b *Breaker) RecordSuccess()
RecordSuccess records a successful operation.
type Config ¶
type Config struct {
// FailureThreshold is the number of consecutive failures before opening the circuit.
FailureThreshold int
// RecoveryTimeout is how long the circuit stays open before transitioning to HalfOpen.
RecoveryTimeout time.Duration
// SuccessThreshold is the number of consecutive successes in HalfOpen before closing.
SuccessThreshold int
}
Config holds circuit breaker parameters.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a production-ready configuration.