-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_list.go
52 lines (47 loc) · 1.06 KB
/
job_list.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package bkp
import (
"github.com/rs/zerolog/log"
"sort"
"strings"
)
type JobList struct {
Jobs []*Job
}
func (j *JobList) Load(sourceDirs []string) {
j.Jobs = AllJobs(sourceDirs)
}
func (j *JobList) Relevant() []*Job {
relevantJobs := make([]*Job, 0)
jobs := j.All()
for _, job := range jobs {
log.Debug().Str("job name", job.Name).Msg("checking if job is relevant")
if job.Target == nil {
log.Fatal().Str("job name", job.Name).Msg("job does not have a target")
continue
}
if !job.IsRelevant() {
log.Debug().Str("job name", job.Name).Msg("job is NOT relevant")
continue
}
if !job.Target.IsReady() {
log.Debug().Str("job name", job.Name).Any("job target", job.Target).Msg("job target is NOT ready")
continue
}
relevantJobs = append(relevantJobs, job)
}
return relevantJobs
}
func (j *JobList) All() []*Job {
// sort
sort.Slice(j.Jobs, func(i, k int) bool {
var (
a = j.Jobs[i]
b = j.Jobs[k]
)
if a.Weight == b.Weight {
return strings.Compare(a.Name, b.Name) == -1
}
return a.Weight < b.Weight
})
return j.Jobs
}