-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (46 loc) · 1.04 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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog/log"
"github.com/smirnoffmg/partner/app"
)
const cancelTimeout = 3 * time.Second
func main() {
sentryDsn := os.Getenv("SENTRY_DSN")
if sentryDsn != "" {
if err := sentry.Init(sentry.ClientOptions{
Dsn: sentryDsn,
}); err != nil {
log.Error().Err(err).Msg("Cannot init sentry")
} else {
defer sentry.Flush(cancelTimeout)
}
}
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill, syscall.SIGTERM)
defer cancel()
if err := run(ctx); err != nil {
log.Error().Err(err).Msg("Run")
defer os.Exit(1)
}
}
func run(ctx context.Context) error {
app, err := app.NewApp()
if err != nil {
log.Error().Err(err).Msg("Cannot create app")
return err
}
if err := app.Start(); err != nil {
log.Error().Err(err).Msg("Problem with bot")
return err
}
<-ctx.Done()
log.Info().Msg("Shutting down (waiting 3 seconds)...")
<-time.After(cancelTimeout)
return nil
}