summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-29 23:17:20 +0300
committerWolfy-J <[email protected]>2018-09-29 23:17:20 +0300
commitc3ca96f4c9057755de78f0484dd3cad35f32c34f (patch)
treebc53ec9b727d5077dc9b8fa73a7cf9072760ea16 /service
parent84d6405ddc232b83bf89594f98b7fcc78a2e8573 (diff)
parent0556629eec5634a7586cc8da56b47e823011ca2c (diff)
Merge branch 'feature/1.2.3' into feature/1.3.0
Diffstat (limited to 'service')
-rw-r--r--service/container.go9
-rw-r--r--service/http/rpc.go33
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
}