Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
e7d499e9bb
  1. 42
      internal/storage/memory/purge.go

42
internal/storage/memory/purge.go

@ -6,7 +6,49 @@
package memory
import (
"time"
"forge.chapril.org/dune/jw"
)
func (ms *memoryStorage) Purge() error {
duration := 7 * 24 * time.Hour
now := time.Now()
deleted := make(map[string]bool)
ms.sm.Lock()
defer ms.sm.Unlock()
workflows := make([]*jw.Workflow, 0, len(ms.workflows))
for _, wf := range ms.workflows {
if wf.FinishedAt != nil || now.After(wf.FinishedAt.Add(duration)) {
deleted[wf.ID] = true
continue
}
workflows = append(workflows, wf)
}
jobs := make([]*jw.Job, 0, len(ms.jobs))
for _, job := range ms.jobs {
if job.Workflow == nil {
if job.FinishedAt != nil && now.After(job.FinishedAt.Add(duration)) {
continue
}
} else if deleted[*(job.Workflow)] {
continue
}
jobs = append(jobs, job)
}
ms.jobs = jobs
ms.workflows = workflows
return nil
}

Loading…
Cancel
Save