-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinfo.go
70 lines (58 loc) · 1.49 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
61
62
63
64
65
66
67
68
69
70
package main
import (
"net/http"
"strconv"
"time"
log "github.com/Sirupsen/logrus"
"github.com/alecthomas/template"
)
type lastJob struct {
JobID string
Region string
Direction string
Time time.Time
}
// LastJobs function updates the lastJobs map with the jobs executed in the last X (INFO_TIME env variable) minutes.
func LastJobs(jobID string, region string, direction string, trigerTime time.Time) {
secs := trigerTime.Unix()
var m lastJob
m.JobID = jobID
m.Region = region
m.Direction = direction
m.Time = trigerTime
lastJobs[secs] = m
}
func clearInfoMap() {
now := time.Now().Unix()
infoTimeInt64, err := strconv.ParseInt(infoTime, 10, 64)
if err != nil {
log.Error("Error converting int to int64 with err: ", err, ". Setting infoTimeInt64 to 60 minutes")
infoTimeInt64 = 60
}
for key := range lastJobs {
if (now - (infoTimeInt64 * 60)) > key {
delete(lastJobs, key)
}
}
}
// StatusPage function returns an html page displaying the last 20 scalling operations performed.
func StatusPage(w http.ResponseWriter, r *http.Request) {
message, err := Asset("templates/info.html")
if err != nil {
log.Error("Error loading asset for info.html with err: ", err)
return
}
messageTmpl, err := template.New("message").Parse(string(message))
if err != nil {
log.Error("Error rendering template for info.html with err: ", err)
return
}
info := struct {
LastJobs map[int64]lastJob
InfoTime string
}{
lastJobs,
infoTime,
}
messageTmpl.Execute(w, info)
}