summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-05-04 19:31:06 +0300
committerWolfy-J <[email protected]>2019-05-04 19:31:06 +0300
commit2afa417f4f46b31b79043e3e56513d51e4ad2fde (patch)
treee3939afb104647e82bd8bbed85f75616c1faf0eb /cmd
parent2efc533f2aac215d487a80020b0f9bf4ae5209c3 (diff)
renamings
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/cmd/root.go6
-rw-r--r--cmd/rr/limit/debug.go71
-rw-r--r--cmd/rr/main.go5
-rw-r--r--cmd/util/debug.go40
4 files changed, 77 insertions, 45 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 1222177a..411391da 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -25,7 +25,7 @@ import (
"github.com/spf13/cobra"
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service"
- "github.com/spiral/roadrunner/service/watcher"
+ "github.com/spiral/roadrunner/service/limit"
"os"
)
@@ -110,8 +110,8 @@ func init() {
// global watcher config
if Verbose {
- wcv, _ := Container.Get(watcher.ID)
- if wcv, ok := wcv.(*watcher.Service); ok {
+ wcv, _ := Container.Get(limit.ID)
+ if wcv, ok := wcv.(*limit.Service); ok {
wcv.AddListener(func(event int, ctx interface{}) {
util.LogEvent(Logger, event, ctx)
})
diff --git a/cmd/rr/limit/debug.go b/cmd/rr/limit/debug.go
new file mode 100644
index 00000000..bb25d099
--- /dev/null
+++ b/cmd/rr/limit/debug.go
@@ -0,0 +1,71 @@
+package limit
+
+import (
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+ "github.com/spiral/roadrunner"
+ rr "github.com/spiral/roadrunner/cmd/rr/cmd"
+ "github.com/spiral/roadrunner/cmd/util"
+ "github.com/spiral/roadrunner/service/limit"
+)
+
+func init() {
+ cobra.OnInitialize(func() {
+ if rr.Debug {
+ svc, _ := rr.Container.Get(limit.ID)
+ if svc, ok := svc.(*limit.Service); ok {
+ svc.AddListener((&debugger{logger: rr.Logger}).listener)
+ }
+ }
+ })
+}
+
+// listener provide debug callback for system events. With colors!
+type debugger struct{ logger *logrus.Logger }
+
+// listener listens to http events and generates nice looking output.
+func (s *debugger) listener(event int, ctx interface{}) {
+ if util.LogEvent(s.logger, event, ctx) {
+ // handler by default debug package
+ return
+ }
+
+ // watchers
+ switch event {
+ case limit.EventMaxTTL:
+ w := ctx.(roadrunner.WorkerError)
+ s.logger.Debug(util.Sprintf(
+ "<white+hb>worker.%v</reset> <yellow>%s</reset>",
+ *w.Worker.Pid,
+ w.Caused,
+ ))
+ return
+
+ case limit.EventMaxIdleTTL:
+ w := ctx.(roadrunner.WorkerError)
+ s.logger.Debug(util.Sprintf(
+ "<white+hb>worker.%v</reset> <yellow>%s</reset>",
+ *w.Worker.Pid,
+ w.Caused,
+ ))
+ return
+
+ case limit.EventMaxMemory:
+ w := ctx.(roadrunner.WorkerError)
+ s.logger.Error(util.Sprintf(
+ "<white+hb>worker.%v</reset> <red>%s</reset>",
+ *w.Worker.Pid,
+ w.Caused,
+ ))
+ return
+
+ case limit.EventMaxExecTTL:
+ w := ctx.(roadrunner.WorkerError)
+ s.logger.Error(util.Sprintf(
+ "<white+hb>worker.%v</reset> <red>%s</reset>",
+ *w.Worker.Pid,
+ w.Caused,
+ ))
+ return
+ }
+}
diff --git a/cmd/rr/main.go b/cmd/rr/main.go
index dc2fbc20..196bede3 100644
--- a/cmd/rr/main.go
+++ b/cmd/rr/main.go
@@ -24,16 +24,17 @@ package main
import (
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
- "github.com/spiral/roadrunner/service/watcher"
// services (plugins)
"github.com/spiral/roadrunner/service/env"
"github.com/spiral/roadrunner/service/http"
+ "github.com/spiral/roadrunner/service/limit"
"github.com/spiral/roadrunner/service/rpc"
"github.com/spiral/roadrunner/service/static"
// additional commands and debug handlers
_ "github.com/spiral/roadrunner/cmd/rr/http"
+ _ "github.com/spiral/roadrunner/cmd/rr/limit"
)
func main() {
@@ -41,7 +42,7 @@ func main() {
rr.Container.Register(rpc.ID, &rpc.Service{})
rr.Container.Register(http.ID, &http.Service{})
rr.Container.Register(static.ID, &static.Service{})
- rr.Container.Register(watcher.ID, &watcher.Service{})
+ rr.Container.Register(limit.ID, &limit.Service{})
// you can register additional commands using cmd.CLI
rr.Execute()
diff --git a/cmd/util/debug.go b/cmd/util/debug.go
index c120eba2..9b94510d 100644
--- a/cmd/util/debug.go
+++ b/cmd/util/debug.go
@@ -3,7 +3,6 @@ package util
import (
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
- "github.com/spiral/roadrunner/service/watcher"
"strings"
)
@@ -58,44 +57,5 @@ func LogEvent(logger *logrus.Logger, event int, ctx interface{}) bool {
return true
}
- // watchers
- switch event {
- case watcher.EventMaxTTL:
- w := ctx.(roadrunner.WorkerError)
- logger.Debug(Sprintf(
- "<white+hb>worker.%v</reset> <yellow>%s</reset>",
- *w.Worker.Pid,
- w.Caused,
- ))
- return true
-
- case watcher.EventMaxIdleTTL:
- w := ctx.(roadrunner.WorkerError)
- logger.Debug(Sprintf(
- "<white+hb>worker.%v</reset> <yellow>%s</reset>",
- *w.Worker.Pid,
- w.Caused,
- ))
- return true
-
- case watcher.EventMaxMemory:
- w := ctx.(roadrunner.WorkerError)
- logger.Error(Sprintf(
- "<white+hb>worker.%v</reset> <red>%s</reset>",
- *w.Worker.Pid,
- w.Caused,
- ))
- return true
-
- case watcher.EventMaxExecTTL:
- w := ctx.(roadrunner.WorkerError)
- logger.Error(Sprintf(
- "<white+hb>worker.%v</reset> <red>%s</reset>",
- *w.Worker.Pid,
- w.Caused,
- ))
- return true
- }
-
return false
}