-
Notifications
You must be signed in to change notification settings - Fork 3
/
job.go
63 lines (53 loc) · 1.34 KB
/
job.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
package main
import (
"github.com/sysward/sysward-agent/logging"
"encoding/json"
"errors"
"fmt"
)
type Job struct {
JobId int `json:"job_id"`
JobType string `json:"job_type"`
PackageName string `json:"package_name"`
}
func (job *Job) run() {
var err error
if job.JobType == "upgrade-package" {
logging.LogMsg(fmt.Sprintf("[apt] upgrading: %s", job.PackageName))
err = packageManager.UpdatePackage(job.PackageName)
} else if job.JobType == "hold-package" {
err = packageManager.HoldPackage(job.PackageName)
} else if job.JobType == "unhold-package" {
err = packageManager.UnholdPackage(job.PackageName)
} else {
err = errors.New(fmt.Sprintf("[job] Unknown job type: %s", job.JobType))
}
if err != nil {
logging.LogMsg(err.Error())
api.JobFailure(*job, err.Error())
} else {
logging.LogMsg(fmt.Sprintf("[job] Posting back for job: %d", job.JobId))
api.JobPostBack(*job)
}
}
func runAllJobs(jobs []Job) {
for index, job := range jobs {
logging.LogMsg(fmt.Sprintf("Running job %d", index))
job.run()
PingApi()
}
}
func getJobs(config ConfigSettings) []Job {
var jobs []Job
jobsResponse := api.GetJobs()
logging.LogMsg(jobsResponse)
if jobsResponse == "{}" || jobsResponse == "" {
return jobs
} else {
err := json.Unmarshal([]byte(jobsResponse), &jobs)
if err != nil {
panic(err)
}
}
return jobs
}