Documentation
¶
Overview ¶
Package breaker is a small circuit breaker for dependencies that fail persistently (MCP servers, model APIs): after a run of failures calls are refused for a cooldown that grows with each failed trial.
Index ¶
Constants ¶
const ( InitialCooldown = 15 * time.Second MaxCooldown = 5 * time.Minute )
How long an open breaker refuses calls: InitialCooldown after the first trip, doubling on each failed trial up to MaxCooldown.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Breaker ¶
type Breaker struct {
// contains filtered or unexported fields
}
Breaker opens after Threshold consecutive failures: calls are refused immediately for a cooldown that doubles on each failed trial (from InitialCooldown up to MaxCooldown). When the cooldown ends, one caller is let through as a trial; success closes the breaker, failure reopens it. It is safe for concurrent use.
func New ¶
New returns a closed breaker that opens after threshold consecutive failures (minimum 1).
func (*Breaker) Abandon ¶
func (b *Breaker) Abandon()
Abandon releases a call Allow let through without recording an outcome (it was cancelled), so a half-open breaker can admit another trial.
func (*Breaker) Allow ¶
Allow reports whether a call may proceed; if not, retryIn says when the next trial is due.
func (*Breaker) Failure ¶
Failure records a failed call. streak is the number of consecutive failures; opened is true when this failure opened (or reopened) the breaker, with the cooldown that now applies.