implement graceful shutdown (#260)

Signed-off-by: Naveen Ramanathan <nramanathan@infoblox.com>
This commit is contained in:
Naveen Ramanathan 2022-03-30 00:41:56 +05:30 committed by GitHub
parent 365078470b
commit d1a8a586ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -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 (

View File

@ -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
}

View File

@ -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")