MCPcopy Create free account
hub / github.com/krau/SaveAny-Bot / CleanupExpired

Function CleanupExpired

api/progress.go:96–109  ·  view source on GitHub ↗

CleanupExpired removes tasks that reached a terminal state more than the store's retention duration ago. It is safe to call periodically.

()

Source from the content-addressed store, hash-verified

94// CleanupExpired removes tasks that reached a terminal state more than the
95// store's retention duration ago. It is safe to call periodically.
96func CleanupExpired() {
97 now := time.Now()
98 store.mu.Lock()
99 defer store.mu.Unlock()
100 for id, info := range store.tasks {
101 info.mu.Lock()
102 terminal := info.Status == TaskStatusCompleted || info.Status == TaskStatusFailed || info.Status == TaskStatusCancelled
103 stale := terminal && now.Sub(info.UpdatedAt) > store.retention
104 info.mu.Unlock()
105 if stale {
106 delete(store.tasks, id)
107 }
108 }
109}
110
111// StartCleanupLoop runs CleanupExpired on a fixed interval until ctx is done.
112// It should be started once during API server initialization.

Callers 1

StartCleanupLoopFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected