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

Method recordFailure

maintnotifications/circuit_breaker.go:137–160  ·  view source on GitHub ↗

recordFailure records a failure and potentially opens the circuit

()

Source from the content-addressed store, hash-verified

135
136// recordFailure records a failure and potentially opens the circuit
137func (cb *CircuitBreaker) recordFailure() {
138 cb.lastFailureTime.Store(time.Now().Unix())
139 failures := cb.failures.Add(1)
140
141 state := CircuitBreakerState(cb.state.Load())
142
143 switch state {
144 case CircuitBreakerClosed:
145 if failures >= int64(cb.failureThreshold) {
146 if cb.state.CompareAndSwap(int32(CircuitBreakerClosed), int32(CircuitBreakerOpen)) {
147 if internal.LogLevel.WarnOrAbove() {
148 internal.Logger.Printf(context.Background(), logs.CircuitBreakerOpened(cb.endpoint, failures))
149 }
150 }
151 }
152 case CircuitBreakerHalfOpen:
153 // Any failure in half-open state immediately opens the circuit
154 if cb.state.CompareAndSwap(int32(CircuitBreakerHalfOpen), int32(CircuitBreakerOpen)) {
155 if internal.LogLevel.WarnOrAbove() {
156 internal.Logger.Printf(context.Background(), logs.CircuitBreakerReopened(cb.endpoint))
157 }
158 }
159 }
160}
161
162// recordSuccess records a success and potentially closes the circuit
163func (cb *CircuitBreaker) recordSuccess() {

Callers 2

ExecuteMethod · 0.95

Calls 7

CircuitBreakerOpenedFunction · 0.92
CircuitBreakerReopenedFunction · 0.92
CircuitBreakerStateTypeAlias · 0.85
WarnOrAboveMethod · 0.80
AddMethod · 0.65
PrintfMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected