chore(graceful): support custom timeout value (#466)

fixed: https://github.com/appleboy/gorush/issues/465
This commit is contained in:
Bo-Yi Wu
2020-02-05 23:23:16 +08:00
committed by GitHub
parent eba8c2d4a6
commit c379630c29
7 changed files with 19 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"sync"
"time"
"github.com/appleboy/gorush/gorush"
"github.com/appleboy/gorush/rpc/proto"
@@ -122,6 +123,9 @@ func RunGRPCServer(ctx context.Context) error {
g.Go(func() error {
select {
case <-ctx.Done():
timeout := time.Duration(gorush.PushConf.Core.ShutdownTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return srv.Shutdown(ctx)
}
})