-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
62 lines (51 loc) · 1.42 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"log"
"os"
"sync"
"time"
"github.com/go-resty/resty/v2"
"github.com/nityanandagohain/yield-chaser/client"
"github.com/nityanandagohain/yield-chaser/controllers"
"github.com/prometheus/client_golang/prometheus"
)
var server = controllers.Server{}
var gaugeVector = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "APY_CHANGE_GAGUE",
Help: "No of request handled by Ping handler",
},
[]string{"APY_CHANGE"},
)
func monitor(shutdownChannel chan bool, waitGroup *sync.WaitGroup, name string) {
log.Println("Starting work goroutine...")
defer waitGroup.Done()
restyClient := resty.New()
for {
select {
case <-shutdownChannel:
log.Println("Shutting down channel: ", name)
return
default:
log.Println("Feching new data from : ", name)
client.GetNewFarms(restyClient)
time.Sleep(time.Hour * 1)
}
}
}
func main() {
log.Println("Starting application...")
shutdownChannel := make(chan bool)
waitGroup := &sync.WaitGroup{}
waitGroup.Add(1)
go monitor(shutdownChannel, waitGroup, "zapper")
port := os.Getenv("PORT") //Get port from .env file, we did not specify any port so this should return an empty string when tested locally
if port == "" {
port = "8090" //localhost
}
server.Initialize(os.Getenv("DATABASE_URL"), ":"+port)
shutdownChannel <- true
log.Println("Received quit. Sending shutdown and waiting on goroutines...")
waitGroup.Wait()
log.Println("Done.")
}