-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 loc) · 1.12 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
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"webtrack/autoini"
"webtrack/mongodb"
)
func main() {
var config, err = autoini.ReadIni[Config]("config.ini")
if err != nil {
log.Fatal(err)
}
mongo, err := mongodb.NewMongoDB(config.MongodbConnectionUrl, config.DatabaseName)
if err != nil {
log.Fatal(err)
}
defer mongo.Disconnect()
// Create the default versions collection
err = mongo.CreateCollection(config.VersionCollectionName)
if err != nil {
log.Fatal(err)
}
var dir = "./queries"
var stopRequest = make(chan any)
var stopResponse = make(chan any)
err = StartTrackers(ListIniFiles(dir), config, mongo, stopRequest, stopResponse)
if err != nil {
log.Fatal(err)
}
fmt.Println("webtrack initialized. Waiting for termination...")
awaitTermination()
fmt.Println("Gracefully exiting...")
close(stopRequest)
<-stopResponse
}
func awaitTermination() {
wait := make(chan any)
go func() {
c := make(chan os.Signal, 1) // Need to reserve a buffer of size 1, otherwise the notifier will be blocked
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
close(wait)
}()
<-wait
}