-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (53 loc) · 1.69 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
package main
import (
"Caronte/dashboard"
scheduler "Caronte/helper"
"Caronte/metrics_publisher"
"Caronte/orchestrator/discovery"
"context"
"flag"
"os"
"os/signal"
"time"
"go.uber.org/zap"
)
var logger *zap.Logger
func main() {
ctx := context.Background()
logLevel := flag.String("log.level", "INFO", "Define Log level {DEBUG or PROD}. Default value prod")
enableDashboard := flag.Bool("dashboard", false, "Activate Dashboard")
dashboardPort := flag.Int("dashboard.port", 80, "Dashboard port listener")
schedulerDiscoveryTime := flag.Int("service.scheduler.discovery.time", 30, "Seconds to raise scale logic")
sqsMetricPublisherQueuename := flag.String("sqs.metic.publisher.queue.name", "", "")
sqsMetricPublisherQueueTime := flag.Int("sqs.metic.publisher.queue.time", 5, "")
flag.Parse()
if *logLevel == "DEBUG" {
logger, _ = zap.NewDevelopment()
} else {
logger, _ = zap.NewProduction()
}
defer logger.Sync()
undo := zap.ReplaceGlobals(logger)
defer undo()
zap.S().Info("Caronte init")
//Init Scheduled Routines
worker := scheduler.NewScheduler()
//Init Caronte Service Discovery
serviceDiscovery, err := discovery.NewDiscovery()
if err == nil {
serviceDiscovery.CaronteServiceDiscovery(ctx)
worker.Add(ctx, serviceDiscovery.CaronteServiceDiscovery, time.Second*time.Duration(*schedulerDiscoveryTime))
} else {
zap.S().Error(err)
}
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Interrupt)
//TODO load metrics dynamicaly
go metrics_publisher.Init(2112)
go metrics_publisher.SQSrecordMetrics(*sqsMetricPublisherQueuename, *sqsMetricPublisherQueueTime)
if *enableDashboard {
go dashboard.Dashboard(*dashboardPort)
}
<-quit
worker.Stop()
}