diff options
author | Wolfy-J <[email protected]> | 2018-06-03 21:49:57 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-03 21:49:57 +0300 |
commit | ed2719f7d4fc4ccde61e3a5c104a49b7e9e9ea5f (patch) | |
tree | a2a005a037cd1b1a959fc6a2323b4908d341a087 /http | |
parent | 7877e54547d1f8ca3b3431c6e9aa3cbd80af1403 (diff) |
error handling
Diffstat (limited to 'http')
-rw-r--r-- | http/rpc.go | 16 | ||||
-rw-r--r-- | http/service.go | 16 |
2 files changed, 31 insertions, 1 deletions
diff --git a/http/rpc.go b/http/rpc.go index dcf19b1f..38db9a61 100644 --- a/http/rpc.go +++ b/http/rpc.go @@ -3,6 +3,7 @@ package http import ( "github.com/sirupsen/logrus" "github.com/spiral/roadrunner/utils" + "github.com/pkg/errors" ) type rpcServer struct { @@ -17,14 +18,27 @@ type WorkerList struct { // Reset resets underlying RR worker pool and restarts all of it's workers. func (rpc *rpcServer) Reset(reset bool, r *string) error { + if rpc.service.srv == nil { + return errors.New("no http server") + } + logrus.Info("http: restarting worker pool") *r = "OK" - return rpc.service.srv.rr.Reset() + err := rpc.service.srv.rr.Reset() + if err != nil { + logrus.Errorf("http: %s", err) + } + + return err } // Workers returns list of active workers and their stats. func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { + if rpc.service.srv == nil { + return errors.New("no http server") + } + r.Workers = utils.FetchWorkers(rpc.service.srv.rr) return nil } diff --git a/http/service.go b/http/service.go index 554b79e3..f8e05f4d 100644 --- a/http/service.go +++ b/http/service.go @@ -5,6 +5,7 @@ import ( "github.com/sirupsen/logrus" "github.com/spiral/roadrunner/service" "net/http" + "github.com/spiral/roadrunner" ) type Service struct { @@ -49,6 +50,21 @@ func (s *Service) Serve() error { } defer term() + rr.Observe(func(event int, ctx interface{}) { + switch event { + case roadrunner.EventPoolError: + logrus.Error(ctx) + case roadrunner.EventWorkerCreate: + logrus.Infof("%s - created", ctx) + case roadrunner.EventWorkerError: + logrus.Errorf("%s: %s", ctx.(roadrunner.WorkerError).Worker, ctx.(roadrunner.WorkerError).Error()) + case roadrunner.EventWorkerDestruct: + logrus.Warnf("%s - destructed", ctx) + case roadrunner.EventWorkerKill: + logrus.Warnf("%s - killed", ctx) + } + }) + s.srv = NewServer(s.cfg.httpConfig(), rr) s.http = &http.Server{ Addr: s.cfg.httpAddr(), |