/
crons_remote_hour.go
82 lines (70 loc) · 1.9 KB
/
crons_remote_hour.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package units
import (
"context"
"fmt"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/utility"
"github.com/mongodb/amboy"
"github.com/mongodb/amboy/job"
"github.com/mongodb/amboy/registry"
"github.com/mongodb/grip"
"github.com/mongodb/grip/message"
"github.com/pkg/errors"
)
const cronsRemoteHourJobName = "crons-remote-hour"
func init() {
registry.AddJobType(cronsRemoteHourJobName, NewCronRemoteHourJob)
}
type cronsRemoteHourJob struct {
job.Base `bson:"job_base" json:"job_base" yaml:"job_base"`
ErrorCount int `bson:"error_count" json:"error_count" yaml:"error_count"`
env evergreen.Environment
}
func NewCronRemoteHourJob() amboy.Job {
j := &cronsRemoteHourJob{
Base: job.Base{
JobType: amboy.JobType{
Name: cronsRemoteHourJobName,
Version: 0,
},
},
}
j.SetID(fmt.Sprintf("%s.%s", cronsRemoteHourJobName, utility.RoundPartOfHour(0).Format(TSFormat)))
return j
}
func (j *cronsRemoteHourJob) Run(ctx context.Context) {
defer j.MarkComplete()
if j.env == nil {
j.env = evergreen.GetEnvironment()
}
ops := []amboy.QueueOperation{
PopulateCacheHistoricalTaskDataJob(2),
PopulateHostProvisioningConversionJobs(j.env),
PopulateHostRestartJasperJobs(j.env),
PopulateSpawnhostExpirationCheckJob(),
PopulateCloudCleanupJob(j.env),
PopulateVolumeExpirationCheckJob(),
PopulateVolumeExpirationJob(),
PopulateUnstickVolumesJob(),
PopulateSSHKeyUpdates(j.env),
PopulateDuplicateTaskCheckJobs(),
PopulatePodResourceCleanupJobs(),
PopulateUnexpirableSpawnHostStatsJob(),
}
queue := j.env.RemoteQueue()
catcher := grip.NewBasicCatcher()
for _, op := range ops {
if ctx.Err() != nil {
j.AddError(errors.New("operation aborted"))
}
catcher.Add(op(ctx, queue))
}
j.ErrorCount = catcher.Len()
grip.Debug(message.Fields{
"queue": "service",
"id": j.ID(),
"type": j.Type().Name,
"num": len(ops),
"errs": j.ErrorCount,
})
}