-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmain.go
84 lines (65 loc) · 1.71 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/renderedtext/go-watchman"
cleaner "github.com/semaphoreio/semaphore/repohub/pkg/cleaner"
fetcher "github.com/semaphoreio/semaphore/repohub/pkg/fetcher"
hub "github.com/semaphoreio/semaphore/repohub/pkg/hub"
metrics "github.com/semaphoreio/semaphore/repohub/pkg/metrics"
)
var (
metricPrefix = fmt.Sprintf("%s.%s", "repohub", os.Getenv("METRICS_NAMESPACE"))
startInternalAPI = os.Getenv("START_INTERNAL_API")
startRepoFetcher = os.Getenv("START_REPO_FETCHER")
startCleaner = os.Getenv("START_REPO_CLEANER")
startMonitor = os.Getenv("START_MONITOR")
)
func configureWatchman() {
err := watchman.ConfigureWithOptions(watchman.Options{
Host: "0.0.0.0",
Port: "8125",
MetricsChannel: watchman.InternalOnly,
BackendType: watchman.BackendGraphite,
MetricPrefix: metricPrefix,
ConnectionAttempts: 30,
ConnectionAttemptWait: 2 * time.Second,
})
if err != nil {
log.Printf("(err) Failed to configure watchman")
}
}
func main() {
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
configureWatchman()
db := hub.DbConnection()
if startRepoFetcher == "yes" {
log.Println("Starting Repository Fetcher")
go func() {
fetcher.NewFetcher(db).Run()
}()
}
if startCleaner == "yes" {
log.Println("Starting Repository Cleaner")
go func() {
cleaner.Run(db)
}()
}
if startMonitor == "yes" {
log.Println("Starting Monitor")
go func() {
metrics.Run(db)
}()
}
if startInternalAPI == "yes" {
log.Println("Starting Internal API")
go func() {
hub.RunServer(db, 50051)
}()
}
log.Println("RepoHub Fully Working")
// sleep forever
select {}
}