diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/container.go | 9 | ||||
-rw-r--r-- | service/http/rpc.go | 33 |
2 files changed, 7 insertions, 35 deletions
diff --git a/service/container.go b/service/container.go index fc1012c8..0ddb4251 100644 --- a/service/container.go +++ b/service/container.go @@ -95,8 +95,6 @@ func (c *container) Register(name string, service interface{}) { svc: service, status: StatusRegistered, }) - - c.log.Debugf("[%s]: registered", name) } // Check hasStatus svc has been registered. @@ -138,14 +136,13 @@ func (c *container) Init(cfg Config) error { if ok, err := c.initService(e.svc, cfg.Get(e.name)); err != nil { // soft error (skipping) if err == errNoConfig { - c.log.Debugf("[%s]: no config has been provided", e.name) + c.log.Debugf("[%s]: disabled", e.name) continue } return errors.Wrap(err, fmt.Sprintf("[%s]", e.name)) } else if ok { e.setStatus(StatusOK) - c.log.Debugf("[%s]: initiated", e.name) } else { c.log.Debugf("[%s]: disabled", e.name) } @@ -168,7 +165,7 @@ func (c *container) Serve() error { continue } - c.log.Debugf("[%s]: service started", e.name) + c.log.Debugf("[%s]: started", e.name) go func(e *entry) { e.setStatus(StatusServing) defer e.setStatus(StatusStopped) @@ -202,8 +199,6 @@ func (c *container) Serve() error { // Stop sends stop command to all running services. func (c *container) Stop() { - c.log.Debugf("received stop command") - for _, e := range c.services { if e.hasStatus(StatusServing) { e.svc.(Service).Stop() diff --git a/service/http/rpc.go b/service/http/rpc.go index 9dfe718e..08b3f262 100644 --- a/service/http/rpc.go +++ b/service/http/rpc.go @@ -2,6 +2,7 @@ package http import ( "github.com/pkg/errors" + "github.com/spiral/roadrunner/util" ) type rpcServer struct{ svc *Service } @@ -9,22 +10,7 @@ type rpcServer struct{ svc *Service } // WorkerList contains list of workers. type WorkerList struct { // Workers is list of workers. - Workers []Worker `json:"workers"` -} - -// Worker provides information about specific worker. -type Worker struct { - // Pid contains process id. - Pid int `json:"pid"` - - // Status of the worker. - Status string `json:"status"` - - // Number of worker executions. - NumJobs int64 `json:"numExecs"` - - // Created is unix nano timestamp of worker creation time. - Created int64 `json:"created"` + Workers []*util.State `json:"workers"` } // Reset resets underlying RR worker pool and restarts all of it's workers. @@ -38,20 +24,11 @@ func (rpc *rpcServer) Reset(reset bool, r *string) error { } // Workers returns list of active workers and their stats. -func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { +func (rpc *rpcServer) Workers(list bool, r *WorkerList) (err error) { if rpc.svc == nil || rpc.svc.srv == nil { return errors.New("http server is not running") } - for _, w := range rpc.svc.rr.Workers() { - state := w.State() - r.Workers = append(r.Workers, Worker{ - Pid: *w.Pid, - Status: state.String(), - NumJobs: state.NumExecs(), - Created: w.Created.UnixNano(), - }) - } - - return nil + r.Workers, err = util.ServerState(rpc.svc.rr) + return err } |