Skip to content

Commit

Permalink
implement graceful shutdown (dapr#260)
Browse files Browse the repository at this point in the history
Signed-off-by: Naveen Ramanathan <[email protected]>
  • Loading branch information
naveen1100 authored Mar 29, 2022
1 parent 3650784 commit d1a8a58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions service/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
7 changes: 7 additions & 0 deletions service/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -75,10 +76,16 @@ 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)
}

// Stop stops the previously started service.
func (s *Server) Stop() error {
return s.listener.Close()
}

func (s *Server) GracefulStop() error {
s.grpcServer.GracefulStop()
return nil
}
4 changes: 4 additions & 0 deletions service/http/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d1a8a58

Please sign in to comment.