-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (56 loc) · 1018 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"bda/api"
crawlerCollector "bda/crawler_collector"
"bda/logger"
"bda/models"
pingerCollector "bda/pinger_collector"
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
)
func WaitForDb(log logger.Logger) {
log.Info(logrus.Fields{}, "Waiting for DB")
for {
isLive := true
db, err := models.GetDb()
if err != nil {
isLive = false
}
rawDb, err := db.DB()
if err != nil {
isLive = false
}
err = rawDb.Ping()
if err != nil {
isLive = false
}
if isLive {
break
} else {
log.Info(logrus.Fields{}, "DB unavaiable, waiting")
time.Sleep(5 * time.Second)
continue
}
}
log.Info(logrus.Fields{}, "DB active, continuing")
}
func main() {
log := logger.Logger{
Prefix: "MAIN",
}
WaitForDb(log)
if len(os.Args) > 1 {
switch os.Args[1] {
case "pinger":
pingerCollector.Start()
case "crawler":
crawlerCollector.Start()
case "api":
api.Start()
}
} else {
fmt.Println("Select entrypoint parameter: pinger, crawler or api")
}
}