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

Method cleanup

maintnotifications/circuit_breaker.go:295–333  ·  view source on GitHub ↗

cleanup removes circuit breakers that haven't been accessed recently

()

Source from the content-addressed store, hash-verified

293
294// cleanup removes circuit breakers that haven't been accessed recently
295func (cbm *CircuitBreakerManager) cleanup() {
296 // Prevent concurrent cleanups
297 if !cbm.cleanupMu.TryLock() {
298 return
299 }
300 defer cbm.cleanupMu.Unlock()
301
302 now := time.Now()
303 cutoff := now.Add(-30 * time.Minute).Unix() // 30 minute TTL
304
305 var toDelete []string
306 count := 0
307
308 cbm.breakers.Range(func(key, value interface{}) bool {
309 endpoint := key.(string)
310 entry := value.(*CircuitBreakerEntry)
311
312 count++
313
314 // Remove if not accessed recently
315 if entry.lastAccess.Load() < cutoff {
316 toDelete = append(toDelete, endpoint)
317 }
318
319 return true
320 })
321
322 // Delete expired entries
323 for _, endpoint := range toDelete {
324 cbm.breakers.Delete(endpoint)
325 }
326
327 // Log cleanup results
328 if len(toDelete) > 0 && internal.LogLevel.InfoOrAbove() {
329 internal.Logger.Printf(context.Background(), logs.CircuitBreakerCleanup(len(toDelete), count))
330 }
331
332 cbm.lastCleanup.Store(now.Unix())
333}
334
335// Shutdown stops the cleanup goroutine
336func (cbm *CircuitBreakerManager) Shutdown() {

Callers 1

cleanupLoopMethod · 0.95

Calls 5

CircuitBreakerCleanupFunction · 0.92
InfoOrAboveMethod · 0.80
AddMethod · 0.65
PrintfMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected