Skip to content

Commit

Permalink
multi: configurable RequestShutdown and ShutdownChannel funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Dec 2, 2022
1 parent a53317c commit 7a9c7be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.go
Expand Up @@ -171,6 +171,11 @@ type Config struct {
// the server is going to use to listen for (and issue) shutdown
// commands on.
ShutdownInterceptor signal.Interceptor

// RequestShutdown is a call-back function that can be called in order
// to indicate that pool has received a critical error and needs to shut
// down.
RequestShutdown func()
}

// DebugConfig is a set of debug options used for development and testing only.
Expand Down Expand Up @@ -217,6 +222,7 @@ func DefaultConfig() Config {
// "no value set".
BatchVersion: -1,
},
RequestShutdown: func() {},
}
}

Expand Down
6 changes: 3 additions & 3 deletions rpcserver.go
Expand Up @@ -259,7 +259,7 @@ func (s *rpcServer) serverHandler(blockChan chan int32, blockErrChan chan error)
if err != nil && !errors.Is(err, order.ErrMismatchErr) {
rpcLog.Errorf("Error handling server message: "+
"%v", err)
s.server.cfg.ShutdownInterceptor.RequestShutdown()
s.server.cfg.RequestShutdown()
}

case err := <-s.auctioneer.StreamErrChan:
Expand All @@ -286,7 +286,7 @@ func (s *rpcServer) serverHandler(blockChan chan int32, blockErrChan chan error)
if err != nil {
rpcLog.Errorf("Unable to receive block "+
"notification: %v", err)
s.server.cfg.ShutdownInterceptor.RequestShutdown()
s.server.cfg.RequestShutdown()
}

// In case the server is shutting down.
Expand Down Expand Up @@ -2648,7 +2648,7 @@ func (s *rpcServer) StopDaemon(_ context.Context,
_ *poolrpc.StopDaemonRequest) (*poolrpc.StopDaemonResponse, error) {

rpcLog.Infof("Stop requested through RPC, gracefully shutting down")
s.server.cfg.ShutdownInterceptor.RequestShutdown()
s.server.cfg.RequestShutdown()

return &poolrpc.StopDaemonResponse{}, nil
}
Expand Down
1 change: 1 addition & 0 deletions run.go
Expand Up @@ -18,6 +18,7 @@ func Run(cfg *Config) error {
if err != nil {
return err
}
cfg.RequestShutdown = cfg.ShutdownInterceptor.RequestShutdown

logWriter = build.NewRotatingLogWriter()
SetupLoggers(logWriter, cfg.ShutdownInterceptor)
Expand Down

0 comments on commit 7a9c7be

Please sign in to comment.