forked from shunfei/cronsun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
60 lines (47 loc) · 1.21 KB
/
info.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
package web
import (
"cronsun/db/entries"
"time"
v3 "github.com/coreos/etcd/clientv3"
"cronsun"
"cronsun/conf"
)
type Info struct{}
func (inf *Info) Overview(ctx *Context) {
var overview = struct {
TotalJobs int64 `json:"totalJobs"`
JobExecuted *entries.StatExecuted `json:"jobExecuted"`
JobExecutedDaily []*entries.StatExecuted `json:"jobExecutedDaily"`
}{}
const day = 24 * time.Hour
days := 7
overview.JobExecuted, _ = entries.JobLogStat()
end := time.Now()
begin := end.Add(time.Duration(1-days) * day)
statList, _ := entries.JobLogDailyStat(begin, end)
list := make([]*entries.StatExecuted, days)
cur := begin
for i := 0; i < days; i++ {
date := cur.Format("2006-01-02")
var se *entries.StatExecuted
for j := range statList {
if statList[j].Date == date {
se = statList[j]
statList = statList[1:]
break
}
}
if se != nil {
list[i] = se
} else {
list[i] = &entries.StatExecuted{Date: date}
}
cur = cur.Add(day)
}
overview.JobExecutedDaily = list
gresp, err := cronsun.DefalutClient.Get(conf.Config.Cmd, v3.WithPrefix(), v3.WithCountOnly())
if err == nil {
overview.TotalJobs = gresp.Count
}
outJSON(ctx.W, overview)
}