-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (68 loc) · 2.19 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
package main
import (
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/larskluge/babl-server/kafka"
. "github.com/larskluge/babl-server/utils"
"github.com/larskluge/babl/bablmodule"
"github.com/larskluge/babl/bablutils"
)
const (
Version = "0.7.12"
clientID = "babl-server"
MaxKafkaMessageSize = 1024 * 100 // 100kb
MaxGrpcMessageSize = 1024 * 1024 * 100 // 100mb
)
var (
debug bool // set by cli.go
command string // set by cli.go
CommandTimeout time.Duration // set by cli.go
RestartTimeout time.Duration // set by cli.go
StorageEndpoint string // set by cli.go
ModuleName string // set by cli.go
KafkaFlush bool // set by cli.go
Processing bool
)
func main() {
u := bablutils.NewUpgrade(clientID, os.Args)
u.Update(Version, os.Getenv("BABL_DESIRED_SERVER_VERSION"))
bablutils.PrintPlainVersionAndExit(os.Args, Version)
app := configureCli()
app.Run(os.Args)
}
func run(address string, kafkaBrokers []string) {
log.SetOutput(os.Stderr)
log.SetFormatter(&log.JSONFormatter{})
log.SetLevel(log.InfoLevel)
if debug {
log.SetLevel(log.DebugLevel)
}
if !bablmodule.CheckModuleName(ModuleName) {
log.WithFields(log.Fields{"module": ModuleName}).Fatal("Module name format incorrect")
}
module := bablmodule.New(ModuleName)
module.SetDebug(debug)
interfaces := "GRPC"
if len(kafkaBrokers) > 0 {
interfaces += ",Kafka"
client := kafka.NewClient(kafkaBrokers, clientID, debug)
defer (*client).Close()
clientgroup := kafka.NewClientGroup(kafkaBrokers, clientID, debug)
defer (*clientgroup).Close()
producer := kafka.NewProducer(kafkaBrokers, clientID+".producer")
defer func() {
log.Infof("Producer: Close Producer")
err := (*producer).Close()
Check(err)
}()
go registerModule(producer, ModuleName)
go startWorker(clientgroup, producer, []string{module.KafkaTopicName("IO")})
go listenToMetadata(client)
}
if nullRestartTimeout, _ := time.ParseDuration("0s"); nullRestartTimeout != RestartTimeout {
go scheduleRestart()
}
log.WithFields(log.Fields{"version": Version, "interfaces": interfaces, "debug": debug}).Warn("Start module")
startGrpcServer(address, module)
}