blob: 8bbb6eb7ea0255afb0f2adf3c927f8fc8dda43f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package job
// KeepOldestOnly filters a job list and keeps only the most recent entry for a job name
func KeepOldestOnly(jobs []Job) []Job {
tmpMap := make(map[string]Job)
for _, elt := range jobs {
prev, exists := tmpMap[elt.Name]
if !exists || (exists && prev.Timestamp < elt.Timestamp) {
tmpMap[elt.Name] = elt
}
}
values := make([]Job, 0, len(tmpMap))
for _, value := range tmpMap {
values = append(values, value)
}
return values
}
// KeepSuccessOnly returns only the successful jobs from a job list (suiatble to write a new spool file)
func KeepSuccessOnly(jobs []Job) (result []Job) {
for _, job := range jobs {
if job.Success {
result = append(result, job)
}
}
return
}
|