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

Method recordSuccess

maintnotifications/circuit_breaker.go:163–185  ·  view source on GitHub ↗

recordSuccess records a success and potentially closes the circuit

()

Source from the content-addressed store, hash-verified

161
162// recordSuccess records a success and potentially closes the circuit
163func (cb *CircuitBreaker) recordSuccess() {
164 cb.lastSuccessTime.Store(time.Now().Unix())
165
166 state := CircuitBreakerState(cb.state.Load())
167
168 switch state {
169 case CircuitBreakerClosed:
170 // Reset failure count on success in closed state
171 cb.failures.Store(0)
172 case CircuitBreakerHalfOpen:
173 successes := cb.successes.Add(1)
174
175 // If we've had enough successful requests, close the circuit
176 if successes >= int64(cb.maxRequests) {
177 if cb.state.CompareAndSwap(int32(CircuitBreakerHalfOpen), int32(CircuitBreakerClosed)) {
178 cb.failures.Store(0)
179 if internal.LogLevel.InfoOrAbove() {
180 internal.Logger.Printf(context.Background(), logs.CircuitBreakerClosed(cb.endpoint, successes))
181 }
182 }
183 }
184 }
185}
186
187// GetState returns the current state of the circuit breaker
188func (cb *CircuitBreaker) GetState() CircuitBreakerState {

Callers 2

ExecuteMethod · 0.95

Calls 6

CircuitBreakerClosedFunction · 0.92
CircuitBreakerStateTypeAlias · 0.85
InfoOrAboveMethod · 0.80
AddMethod · 0.65
PrintfMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected