diff --git a/service/common/service.go b/service/common/service.go index cb7f90f..b430b4d 100644 --- a/service/common/service.go +++ b/service/common/service.go @@ -41,6 +41,8 @@ type Service interface { Start() error // Stop stops the previously started service. Stop() error + // Gracefully stops the previous started service + GracefulStop() error } type ( diff --git a/service/grpc/service.go b/service/grpc/service.go index 2fec665..75aa78b 100644 --- a/service/grpc/service.go +++ b/service/grpc/service.go @@ -65,6 +65,7 @@ type Server struct { topicRegistrar internal.TopicRegistrar bindingHandlers map[string]common.BindingInvocationHandler authToken string + grpcServer *grpc.Server } func (s *Server) RegisterActorImplFactory(f actor.Factory, opts ...config.Option) { @@ -75,6 +76,7 @@ func (s *Server) RegisterActorImplFactory(f actor.Factory, opts ...config.Option func (s *Server) Start() error { gs := grpc.NewServer() pb.RegisterAppCallbackServer(gs, s) + s.grpcServer = gs return gs.Serve(s.listener) } @@ -82,3 +84,8 @@ func (s *Server) Start() error { func (s *Server) Stop() error { return s.listener.Close() } + +func (s *Server) GracefulStop() error { + s.grpcServer.GracefulStop() + return nil +} diff --git a/service/http/service.go b/service/http/service.go index 7823e8f..7c553de 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -81,6 +81,10 @@ func (s *Server) Stop() error { return s.httpServer.Shutdown(ctxShutDown) } +func (s *Server) GracefulStop() error { + return s.Stop() +} + func setOptions(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST,OPTIONS")