summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--service/http/service.go10
-rw-r--r--service/watcher/watcher.go8
3 files changed, 15 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index b1a78e02..954dff7a 100644
--- a/Makefile
+++ b/Makefile
@@ -17,3 +17,4 @@ test:
go test -v -race -cover ./service/rpc
go test -v -race -cover ./service/http
go test -v -race -cover ./service/static
+ go test -v -race -cover ./service/watcher
diff --git a/service/http/service.go b/service/http/service.go
index 47175ec3..716499a4 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -33,11 +33,17 @@ type Service struct {
mdwr []middleware
mu sync.Mutex
rr *roadrunner.Server
+ watcher roadrunner.Watcher
handler *Handler
http *http.Server
https *http.Server
}
+// Watch attaches watcher.
+func (s *Service) AttachWatcher(w roadrunner.Watcher) {
+ s.watcher = w
+}
+
// AddMiddleware adds new net/http mdwr.
func (s *Service) AddMiddleware(m middleware) {
s.mdwr = append(s.mdwr, m)
@@ -78,6 +84,10 @@ func (s *Service) Serve() error {
s.rr = roadrunner.NewServer(s.cfg.Workers)
s.rr.Listen(s.throw)
+ if s.watcher != nil {
+ s.rr.Watch(s.watcher)
+ }
+
s.handler = &Handler{cfg: s.cfg, rr: s.rr}
s.handler.Listen(s.throw)
diff --git a/service/watcher/watcher.go b/service/watcher/watcher.go
index 9d770135..10c642cb 100644
--- a/service/watcher/watcher.go
+++ b/service/watcher/watcher.go
@@ -2,8 +2,8 @@ package watcher
import "github.com/spiral/roadrunner"
-// Server defines the ability to get access to underlying roadrunner server for watching capabilities.
-type Server interface {
- // Server must return associated roadrunner serve.
- Server() *roadrunner.Server
+// Watchable defines the ability to attach roadrunner watcher.
+type Watchable interface {
+ // Watch attaches watcher to the service.
+ Watch(w roadrunner.Watcher)
}