-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (37 loc) · 910 Bytes
/
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
package main
import (
"context"
log "github.com/sirupsen/logrus"
"nhl-recap/nhl"
"nhl-recap/telegram"
"nhl-recap/util"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
ctx, cancel := context.WithCancel(context.Background())
gracefulShutdown(cancel)
nhl := nhl.NewNHL()
subscription := util.NewSubscription(ctx, nhl.Fetcher, time.NewTicker(10*time.Minute))
nhlRecapBot := telegram.InitializeBot()
nhlRecapBot.HandleSubscription()
nhlRecapBot.HandleUnsubscription()
nhlRecapBot.SendSubscriptions(subscription)
log.Info("NHL Recap telegram nhlRecapBot is starting...")
nhlRecapBot.Start()
}
func gracefulShutdown(cancel context.CancelFunc) {
s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt)
signal.Notify(s, syscall.SIGTERM)
go func() {
<-s
log.Info("Shutting down gracefully...")
cancel()
os.Exit(0)
}()
}