-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (33 loc) · 893 Bytes
/
main.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
package main
import (
"log"
"os"
"os/signal"
"time"
"github.com/go-co-op/gocron"
"github.com/swathinsankaran/chargemywifi/pkg/metric"
"github.com/swathinsankaran/chargemywifi/pkg/model"
"github.com/swathinsankaran/chargemywifi/pkg/statscollector"
)
func main() {
log.Println("Application Started.")
defer exit()
dBattery := metric.New(model.LabelBatteryQuantity)
dChargeStatus := metric.New(model.LabelChargeStatus)
sc := statscollector.New()
sc.Register(dBattery)
sc.Register(dChargeStatus)
log.Println("Starting cron jobs.")
s := gocron.NewScheduler(time.UTC)
s.Every(1).Minute().Do(sc.Collect)
s.Every(1).StartAt(time.Now().Add(30 * time.Second)).Minute().Do(sc.Notify)
s.StartAsync()
}
func exit() {
exitChannel := make(chan os.Signal)
signal.Notify(exitChannel, os.Kill, os.Interrupt)
select {
case <-exitChannel:
log.Println("Application stopped.")
}
}