-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
78 lines (60 loc) · 1.61 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
package main
import (
"os"
"os/signal"
"github.com/sirupsen/logrus"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"github.com/ritsec/ops-bot-iii/bot"
"github.com/ritsec/ops-bot-iii/commands"
"github.com/ritsec/ops-bot-iii/config"
"github.com/ritsec/ops-bot-iii/logging"
"github.com/ritsec/ops-bot-iii/web"
)
func main() {
// close logging file
defer logging.Out.Close()
// start datadog tracer
tracer.Start(
tracer.WithService(config.ServiceName),
tracer.WithEnv(config.Environment),
)
defer tracer.Stop()
// start main span
span := tracer.StartSpan(
"main",
tracer.ResourceName("main:main"),
)
defer span.Finish()
logging.InfoDD("Bot Starting", span)
// initialize commands
commands.Init(span.Context())
// start bot
err := bot.Session.Open()
if err != nil {
logging.CriticalDD("Bot Session Failed to open", span, logrus.Fields{"error": err})
panic(err)
}
// start scheduled tasks
commands.StartScheduledTasks(span.Context())
logging.Debug(bot.Session, "Finished init", nil, span)
// create stop channel
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
// start web server
logrus.Println("Starting web server")
go web.Start(span.Context())
logging.DebugDD("Web server started", span)
logrus.Println("Press Ctrl+C to exit")
// wait for stop signal
<-stop
// stop scheduled tasks
commands.StopScheduledTasks(span.Context())
// stop bot
err = bot.Session.Close()
if err != nil {
logging.CriticalDD("Bot Session Failed to close", span, logrus.Fields{"error": err})
panic(err)
}
logrus.Println("Bot stopped")
logging.InfoDD("Bot stopping", span)
}