This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (75 loc) · 1.88 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
85
86
87
88
package main
import (
"fmt"
"os"
"strings"
"go.uber.org/zap"
"go.bobheadxi.dev/seer/config"
"go.bobheadxi.dev/zapx/zapx"
)
func main() {
// load up configuration
flags, err := config.LoadFlags(os.Args[1:])
if err != nil {
if strings.Contains(err.Error(), "help requested") {
return
}
panic(err)
}
cfg, err := config.NewEnvConfig()
if err != nil {
panic(err)
}
meta := config.NewBuildMeta()
// init logger
log, err := zapx.New(flags.LogPath, flags.Dev,
zapx.WithDebug(flags.Dev),
zapx.WithFields(map[string]interface{}{
"build.version": meta.Version,
}))
if err != nil {
panic(err)
}
defer log.Sync()
// init dynamic configuration
if !cfg.NoDynamicConfiguration {
log.Info("initializing dynamic configuration")
cfg.InitDynamicConfig(log.Named("dynamic_config"))
} else {
log.Info("dynamic configuration disabled")
}
// report basic config
log.Debug("configuration loaded",
zap.Any("config", cfg),
zap.Any("meta", meta),
zap.Any("flags", flags))
// handle jobs-ui-only mode first
if flags.Mode() == config.ModeJobsUIOnly {
if flags.JobsUIPort == "" {
flags.JobsUIPort = "8081"
}
startJobsUI(log.Named("jobs_ui"), cfg.RedisNamespace, cfg.DefaultRedisPool(), ":"+flags.JobsUIPort)
return
}
// spin up jobs manager UI as well if configured to do so for all other modes
if flags.JobsUIPort != "" {
go startJobsUI(
log.Named("jobs_ui"),
cfg.RedisNamespace,
cfg.DefaultRedisPool(),
":"+flags.JobsUIPort)
}
// handle other operation modes
switch flags.Mode() {
case config.ModeServer:
startServer(log.Named("server"), flags, *cfg, meta)
case config.ModeWorker:
startWorker(log.Named("worker"), flags, *cfg, meta)
case config.ModeAll:
go startServer(log.Named("server"), flags, *cfg, meta)
startWorker(log.Named("worker"), flags, *cfg, meta)
default:
fmt.Printf("unknown mode '%s'", flags.Mode())
os.Exit(1)
}
}