Gestionnaire de jobs et workflows
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
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
}
/*
######################################################################################################## @(°_°)@ #######
*/