mirror of https://github.com/dapr/go-sdk.git
implement graceful shutdown (#260)
Signed-off-by: Naveen Ramanathan <nramanathan@infoblox.com>
This commit is contained in:
parent
365078470b
commit
d1a8a586ea
|
@ -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 (
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue