-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
56 lines (48 loc) · 1.12 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/hashicorp/nomad/api"
)
func main() {
nextGroups := os.Args[1:]
jobId := os.Getenv("NOMAD_JOB_ID")
myGroupName := os.Getenv("NOMAD_GROUP_NAME")
fmt.Printf("next jobs are %#v\n", nextGroups)
client, err := api.NewClient(&api.Config{
Namespace: os.Getenv("NOMAD_NAMESPACE"),
})
handleError(err)
jobs := client.Jobs()
fmt.Printf("getting job: %q\n", jobId)
job, _, err := jobs.Info(jobId, nil)
handleError(err)
for _, g := range nextGroups {
group := job.LookupTaskGroup(g)
if group == nil {
fmt.Fprintf(os.Stderr, "[WARN] could not find next group: %q\n", g)
continue
}
group.Count = i2p(1)
}
if g := job.LookupTaskGroup(myGroupName); g != nil {
g.Count = i2p(0)
} else {
fmt.Fprintf(os.Stderr, "[WARN] could not find my group: %q\n", myGroupName)
}
_, _, err = jobs.RegisterOpts(job, &api.RegisterOptions{
EnforceIndex: true,
ModifyIndex: *job.JobModifyIndex,
}, nil)
handleError(err)
}
func i2p(i int) *int {
return &i
}
func handleError(err error) {
if err == nil {
return
}
fmt.Println("error creating client:", err.Error())
os.Exit(-1)
}