/
cmd_list_jobs.go
50 lines (44 loc) · 1.16 KB
/
cmd_list_jobs.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
package main
import (
"fmt"
"strings"
"github.com/dshearer/jobber/ipc"
"github.com/dshearer/jobber/jobfile"
)
func resultSinksString(sinks []jobfile.ResultSink) string {
var strs []string
for _, sink := range sinks {
strs = append(strs, sink.String())
}
return strings.Join(strs, ",")
}
func (self *JobManager) doListJobsCmd(cmd ipc.ListJobsCmd) ipc.ICmdResp {
// make job list
jobDescs := make([]ipc.JobDesc, 0)
for _, j := range self.jfile.Jobs {
jobDesc := ipc.JobDesc{
Name: j.Name,
Status: j.Status.String(),
Schedule: fmt.Sprintf(
"%v %v %v %v %v %v",
j.FullTimeSpec.Sec,
j.FullTimeSpec.Min,
j.FullTimeSpec.Hour,
j.FullTimeSpec.Mday,
j.FullTimeSpec.Mon,
j.FullTimeSpec.Wday),
NextRunTime: j.NextRunTime,
NotifyOnSuccess: resultSinksString(j.NotifyOnSuccess),
NotifyOnErr: resultSinksString(j.NotifyOnError),
NotifyOnFail: resultSinksString(j.NotifyOnFailure),
ErrHandler: j.ErrorHandler.String(),
}
if j.Paused {
jobDesc.Status += " (Paused)"
jobDesc.NextRunTime = nil
}
jobDescs = append(jobDescs, jobDesc)
}
// make response
return ipc.ListJobsCmdResp{Jobs: jobDescs}
}