-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.go
62 lines (53 loc) · 1.45 KB
/
start.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
package cmd
import (
"os"
"os/signal"
"strings"
"syscall"
log "github.com/codeamp/logger"
"github.com/codeamp/transistor"
uuid "github.com/satori/go.uuid"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var startCmd = &cobra.Command{
Use: "start",
Long: `...`,
Run: func(cmd *cobra.Command, args []string) {
config := transistor.Config{
Server: viper.GetString("redis.server"),
Database: viper.GetString("redis.database"),
Pool: viper.GetString("redis.pool"),
Password: viper.GetString("redis.password"),
Process: uuid.NewV4().String(),
Queueing: true,
Plugins: viper.GetStringMap("plugins"),
EnabledPlugins: viper.GetStringSlice("enable"),
}
t, err := transistor.NewTransistor(config)
if err != nil {
log.Fatal(err)
}
signals := make(chan os.Signal)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-signals
if sig == os.Interrupt || sig == syscall.SIGTERM {
log.Info("Shutting down Circuit. SIGTERM recieved!\n")
// If Queueing is ON then workers are responsible for closing Shutdown chan
if !config.Queueing {
t.Stop()
}
}
}()
log.InfoWithFields("plugins loaded", log.Fields{
"plugins": strings.Join(t.PluginNames(), ","),
})
t.Run()
},
}
func init() {
RootCmd.AddCommand(startCmd)
startCmd.Flags().StringSliceP("enable", "e", []string{}, "websockets")
viper.BindPFlags(startCmd.Flags())
}