-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
48 lines (40 loc) · 851 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
44
45
46
47
48
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/j75689/slack-bot/appruntime"
"github.com/j75689/slack-bot/service"
)
func main() {
go service.Start()
// Wait for interrupt signal to gracefully shutdown the server with
// a timeout of 60 seconds.
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGTERM, os.Interrupt)
<-quit
appruntime.Logger.Info("Shutdown Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
done := make(chan bool)
go func() {
service.Shutdown()
done <- true
}()
wait := make(chan bool)
go func() {
select {
case <-ctx.Done():
appruntime.Logger.Fatal("Server Shutdown Timeout ")
wait <- true
break
case <-done:
wait <- true
break
}
}()
<-wait
appruntime.Logger.Info("Server exiting")
}