-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (69 loc) · 1.74 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 (
"log"
"os"
"github.com/alash3al/exeq/internals/commands"
"github.com/alash3al/exeq/internals/config"
"github.com/alash3al/exeq/internals/queue"
"github.com/alash3al/exeq/pkg/utils"
"github.com/getsentry/sentry-go"
"github.com/kataras/golog"
"github.com/urfave/cli/v2"
_ "github.com/alash3al/exeq/internals/queue/drivers/rmq"
)
var (
cfg *config.Config
queueConn queue.Driver
)
const (
configFileEnvName = "EXEQ_CONFIG"
)
func init() {
var err error
cfg, err = config.BootFromFile(utils.Getenv(configFileEnvName, "./exeq.hcl"))
if err != nil {
golog.Fatal(err)
}
queueConn, err = queue.Open(cfg.Queue.Driver, cfg.Queue)
if err != nil {
golog.Fatal(err)
}
if cfg.Logging.SentryDSN != "" {
if err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
Dsn: cfg.Logging.SentryDSN,
Release: "exeq",
}); err != nil {
log.Fatalf("sentry.Init: %s", err)
}
}
go (func() {
for err := range queueConn.Err() {
golog.Error(err)
if cfg.Logging.SentryDSN != "" {
sentry.CaptureException(err)
}
}
})()
}
func main() {
golog.SetLevel(cfg.Logging.LogLevel)
app := &cli.App{
Name: "exeq",
Version: "1.0.0",
Description: "exeq enables you to execute shell commands in a managed scalable queue",
EnableBashCompletion: true,
UseShortOptionHandling: true,
Commands: []*cli.Command{
commands.QueueWork(cfg, queueConn),
commands.EnqueueMacro(cfg, queueConn),
commands.EnqueueCMD(queueConn),
commands.QueueList(queueConn),
commands.QueueStats(queueConn),
commands.HTTPServer(cfg, queueConn),
},
}
if err := app.Run(os.Args); err != nil {
golog.Fatal(err)
}
}