Skip to content

Commit

Permalink
feat: Implement graceful shutdown
Browse files Browse the repository at this point in the history
Close #20
  • Loading branch information
howjmay committed Dec 10, 2020
1 parent 2167a5b commit 80145e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
24 changes: 22 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"
"time"

"github.com/DropKit/DropKit-Adapter/logger"
routes "github.com/DropKit/DropKit-Adapter/router"
"github.com/DropKit/DropKit-Adapter/services"
"github.com/ethereum/go-ethereum/log"
"github.com/spf13/viper"
)

Expand All @@ -25,6 +32,19 @@ func init() {
}

func main() {
router := routes.SetupRouter()
router.Run(":" + viper.GetString(`DROPKIT.PORT`))
// router := routes.SetupRouter()
_, srv := routes.SetupRouter()
// router.Run(":" + viper.GetString(`DROPKIT.PORT`))

shutdown := make(chan os.Signal)
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
<-shutdown
log.Info("Shutdown Server")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Error("Forced to shutdown server")
}

}
3 changes: 2 additions & 1 deletion router/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ func SetupRouter() *gin.Engine {
{
roleRoute.POST("/create", role.CreateColumnRole)
}
return r

return r, srv
}

0 comments on commit 80145e6

Please sign in to comment.