cronsun/web/info.go

32 lines
748 B
Go
Raw Normal View History

2017-02-20 09:57:22 +00:00
package web
import (
"net/http"
"time"
v3 "github.com/coreos/etcd/clientv3"
2017-05-12 06:48:24 +00:00
"github.com/shunfei/cronsun"
2017-05-12 07:38:50 +00:00
"github.com/shunfei/cronsun/conf"
2017-02-20 09:57:22 +00:00
)
type Info struct{}
func (inf *Info) Overview(w http.ResponseWriter, r *http.Request) {
var overview = struct {
2017-05-12 07:38:50 +00:00
TotalJobs int64 `json:"totalJobs"`
2017-05-12 06:48:24 +00:00
JobExecuted *cronsun.StatExecuted `json:"jobExecuted"`
JobExecutedDaily *cronsun.StatExecuted `json:"jobExecutedDaily"`
2017-02-20 09:57:22 +00:00
}{}
2017-05-12 06:48:24 +00:00
overview.JobExecuted, _ = cronsun.JobLogStat()
overview.JobExecutedDaily, _ = cronsun.JobLogDayStat(time.Now())
2017-02-20 09:57:22 +00:00
2017-05-12 06:48:24 +00:00
gresp, err := cronsun.DefalutClient.Get(conf.Config.Cmd, v3.WithPrefix(), v3.WithCountOnly())
2017-02-20 09:57:22 +00:00
if err == nil {
overview.TotalJobs = gresp.Count
}
outJSON(w, overview)
}