MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / Cleanup

Method Cleanup

internal/bridge/taskmanager.go:317–337  ·  view source on GitHub ↗

Cleanup removes tasks that have been in a terminal state (Completed/Failed) for longer than maxAge, and cleans up their subIndex entries.

(maxAge time.Duration)

Source from the content-addressed store, hash-verified

315// Cleanup removes tasks that have been in a terminal state (Completed/Failed)
316// for longer than maxAge, and cleans up their subIndex entries.
317func (tm *TaskManager) Cleanup(maxAge time.Duration) {
318 cutoff := time.Now().Add(-maxAge)
319
320 tm.mu.Lock()
321 defer tm.mu.Unlock()
322
323 for key, task := range tm.tasks {
324 task.mu.Lock()
325 terminal := task.State == TaskCompleted || task.State == TaskFailed
326 stale := task.UpdatedAt.Before(cutoff)
327 cmds := task.subCmds
328 task.mu.Unlock()
329
330 if terminal && stale {
331 for _, cmdID := range cmds {
332 delete(tm.subIndex, cmdID)
333 }
334 delete(tm.tasks, key)
335 }
336 }
337}
338
339// CleanupLoop runs Cleanup periodically until ctx is cancelled.
340func (tm *TaskManager) CleanupLoop(done <-chan struct{}, maxAge time.Duration) {

Calls

no outgoing calls