MCPcopy
hub / github.com/redis/go-redis / newCircuitBreaker

Function newCircuitBreaker

maintnotifications/circuit_breaker.go:59–79  ·  view source on GitHub ↗

newCircuitBreaker creates a new circuit breaker for an endpoint

(endpoint string, config *Config)

Source from the content-addressed store, hash-verified

57
58// newCircuitBreaker creates a new circuit breaker for an endpoint
59func newCircuitBreaker(endpoint string, config *Config) *CircuitBreaker {
60 // Use configuration values with sensible defaults
61 failureThreshold := 5
62 resetTimeout := 60 * time.Second
63 maxRequests := 3
64
65 if config != nil {
66 failureThreshold = config.CircuitBreakerFailureThreshold
67 resetTimeout = config.CircuitBreakerResetTimeout
68 maxRequests = config.CircuitBreakerMaxRequests
69 }
70
71 return &CircuitBreaker{
72 failureThreshold: failureThreshold,
73 resetTimeout: resetTimeout,
74 maxRequests: maxRequests,
75 endpoint: endpoint,
76 config: config,
77 state: atomic.Int32{}, // Defaults to CircuitBreakerClosed (0)
78 }
79}
80
81// IsOpen returns true if the circuit breaker is open (rejecting requests)
82func (cb *CircuitBreaker) IsOpen() bool {

Callers 3

TestCircuitBreakerFunction · 0.85
GetCircuitBreakerMethod · 0.85

Calls

no outgoing calls

Tested by 2

TestCircuitBreakerFunction · 0.68