forked from bamzi/jobrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
54 lines (39 loc) · 962 Bytes
/
status.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
package jobrunner
import (
"time"
"github.com/robfig/cron/v3"
)
type StatusData struct {
Id cron.EntryID
JobRunner *Job
Next time.Time
Prev time.Time
}
// Return detailed list of currently running recurring jobs
// to remove an entry, first retrieve the ID of entry
func Entries() []cron.Entry {
return MainCron.Entries()
}
func StatusPage() []StatusData {
ents := MainCron.Entries()
Statuses := make([]StatusData, len(ents))
for k, v := range ents {
Statuses[k].Id = v.ID
Statuses[k].JobRunner = AddJob(v.Job)
Statuses[k].Next = v.Next
Statuses[k].Prev = v.Prev
}
// t := template.New("status_page")
// var data bytes.Buffer
// t, _ = t.ParseFiles("views/Status.html")
// t.ExecuteTemplate(&data, "status_page", Statuses())
return Statuses
}
func StatusJson() map[string]interface{} {
return map[string]interface{}{
"jobrunner": StatusPage(),
}
}
func AddJob(job cron.Job) *Job {
return job.(*Job)
}