diff options
author | Anton Titov <[email protected]> | 2019-12-23 14:52:06 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-23 14:52:06 +0300 |
commit | 921e1f55e23ab75b8250045916c8d1ffad1b8bde (patch) | |
tree | 00b16331b9ff3b3b846ba22989dddde721cc959d /service/health/service.go | |
parent | 921354df1aa4687837e3ba6ac0eb04d39321c149 (diff) | |
parent | 2093cb9058f94668fff0a97beb76b0cab66c7b63 (diff) |
Merge branch 'master' into Fix_warning_and_issues
Diffstat (limited to 'service/health/service.go')
-rw-r--r-- | service/health/service.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/service/health/service.go b/service/health/service.go index a730de7e..c82f43b5 100644 --- a/service/health/service.go +++ b/service/health/service.go @@ -3,6 +3,7 @@ package health import ( "context" "fmt" + "github.com/sirupsen/logrus" "net/http" "sync" @@ -15,19 +16,21 @@ const ID = "health" // Service to serve an endpoint for checking the health of the worker pool type Service struct { cfg *Config + log *logrus.Logger mu sync.Mutex http *http.Server httpService *rrhttp.Service } // Init health service -func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) { +func (s *Service) Init(cfg *Config, r *rrhttp.Service, log *logrus.Logger) (bool, error) { // Ensure the httpService is set if r == nil { return false, nil } s.cfg = cfg + s.log = log s.httpService = r return true, nil } @@ -38,7 +41,13 @@ func (s *Service) Serve() error { s.mu.Lock() s.http = &http.Server{Addr: s.cfg.Address, Handler: s} s.mu.Unlock() - return s.http.ListenAndServe() + + err := s.http.ListenAndServe() + if err == nil || err == http.ErrServerClosed { + return nil + } + + return err } // Stop the health endpoint @@ -50,9 +59,8 @@ func (s *Service) Stop() { // gracefully stop the server go func() { err := s.http.Shutdown(context.Background()) - if err != nil { - // TODO how to log error here? - fmt.Println(fmt.Errorf("error shutting down the server: error %v", err)) + if err != nil && err != http.ErrServerClosed { + s.log.Error(fmt.Errorf("error shutting down the metrics server: error %v", err)) } }() } |