summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-29 23:37:16 +0300
committerGitHub <[email protected]>2018-09-29 23:37:16 +0300
commit6122fca108c20984732c969fb1ba53cce5b3c44a (patch)
tree40835f46a5c208ea2546b76e3bd9fa05429b405a /service
parentabe62c0675f839586312cff1c83d6a4cb31dd9d5 (diff)
parenta04b5b33eb30944007973067ec07e9c4a2c464ab (diff)
Merge pull request #39 from spiral/feature/1.3.0v1.2.3
Feature/1.3.0
Diffstat (limited to 'service')
-rw-r--r--service/container.go9
-rw-r--r--service/container_test.go35
-rw-r--r--service/http/handler.go5
-rw-r--r--service/http/request.go6
-rw-r--r--service/http/rpc.go33
-rw-r--r--service/http/uploads.go3
6 files changed, 29 insertions, 62 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/container_test.go b/service/container_test.go
index 8eeb647a..7d83ee9a 100644
--- a/service/container_test.go
+++ b/service/container_test.go
@@ -117,7 +117,7 @@ func TestContainer_Register(t *testing.T) {
c := NewContainer(logger)
c.Register("test", &testService{})
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
}
func TestContainer_Has(t *testing.T) {
@@ -127,7 +127,7 @@ func TestContainer_Has(t *testing.T) {
c := NewContainer(logger)
c.Register("test", &testService{})
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.True(t, c.Has("test"))
assert.False(t, c.Has("another"))
@@ -139,8 +139,7 @@ func TestContainer_Get(t *testing.T) {
c := NewContainer(logger)
c.Register("test", &testService{})
-
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
@@ -157,7 +156,7 @@ func TestContainer_Stop_NotStarted(t *testing.T) {
c := NewContainer(logger)
c.Register("test", &testService{})
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
c.Stop()
}
@@ -170,7 +169,7 @@ func TestContainer_Configure(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something"}`}))
@@ -187,7 +186,7 @@ func TestContainer_Init_Default(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{}`}))
@@ -206,7 +205,7 @@ func TestContainer_Init_Default_Overwrite(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":{"value": "something"}}`}))
@@ -225,10 +224,10 @@ func TestContainer_ConfigureNull(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"another":"something"}`}))
- assert.Equal(t, 2, len(hook.Entries))
+ assert.Equal(t, 1, len(hook.Entries))
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
@@ -243,10 +242,10 @@ func TestContainer_ConfigureDisabled(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something"}`}))
- assert.Equal(t, 2, len(hook.Entries))
+ assert.Equal(t, 1, len(hook.Entries))
s, st := c.Get("test")
assert.IsType(t, &testService{}, s)
@@ -264,7 +263,7 @@ func TestContainer_ConfigureError(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
err := c.Init(&testCfg{`{"test":"something"}`})
assert.Error(t, err)
@@ -284,7 +283,7 @@ func TestContainer_ConfigureTwice(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something"}`}))
assert.Error(t, c.Init(&testCfg{`{"test":"something"}`}))
@@ -298,7 +297,7 @@ func TestContainer_ServeEmptyContainer(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Serve())
c.Stop()
@@ -315,7 +314,7 @@ func TestContainer_Serve(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something"}`}))
go func() {
@@ -347,7 +346,7 @@ func TestContainer_ServeError(t *testing.T) {
c := NewContainer(logger)
c.Register("test", svc)
- assert.Equal(t, 1, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something"}`}))
err := c.Serve()
@@ -379,7 +378,7 @@ func TestContainer_ServeErrorMultiple(t *testing.T) {
c := NewContainer(logger)
c.Register("test2", svc2)
c.Register("test", svc)
- assert.Equal(t, 2, len(hook.Entries))
+ assert.Equal(t, 0, len(hook.Entries))
assert.NoError(t, c.Init(&testCfg{`{"test":"something", "test2":"something-else"}`}))
err := c.Serve()
diff --git a/service/http/handler.go b/service/http/handler.go
index 945cd51e..f719c751 100644
--- a/service/http/handler.go
+++ b/service/http/handler.go
@@ -72,10 +72,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
- if err = req.Open(); err != nil {
- h.handleError(w, r, err)
- return
- }
+ req.Open()
defer req.Close()
p, err := req.Payload()
diff --git a/service/http/request.go b/service/http/request.go
index d733b20c..eb5c05bd 100644
--- a/service/http/request.go
+++ b/service/http/request.go
@@ -109,12 +109,12 @@ func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error) {
}
// Open moves all uploaded files to temporary directory so it can be given to php later.
-func (r *Request) Open() error {
+func (r *Request) Open() {
if r.Uploads == nil {
- return nil
+ return
}
- return r.Uploads.Open()
+ r.Uploads.Open()
}
// Close clears all temp file uploads
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
}
diff --git a/service/http/uploads.go b/service/http/uploads.go
index 9b205f00..7610ab28 100644
--- a/service/http/uploads.go
+++ b/service/http/uploads.go
@@ -45,7 +45,7 @@ func (u *Uploads) MarshalJSON() ([]byte, error) {
// Open moves all uploaded files to temp directory, return error in case of issue with temp directory. File errors
// will be handled individually.
-func (u *Uploads) Open() error {
+func (u *Uploads) Open() {
var wg sync.WaitGroup
for _, f := range u.list {
wg.Add(1)
@@ -56,7 +56,6 @@ func (u *Uploads) Open() error {
}
wg.Wait()
- return nil
}
// Clear deletes all temporary files.