summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-05-03 15:44:51 +0300
committerWolfy-J <[email protected]>2019-05-03 15:44:51 +0300
commit28c787d66c2b74dd2300c792abd1e4f987c3d6c9 (patch)
treeb9c5ef036eda3ffa16b5e87a06ce99fcd8a4d7b4 /cmd
parente9d42947a6922ce2f0aa9f9bcab4ead167735bc9 (diff)
new watchers functionality
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/cmd/root.go11
-rw-r--r--cmd/rr/main.go2
-rw-r--r--cmd/util/debug.go24
3 files changed, 35 insertions, 2 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 74506004..2e170307 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -25,10 +25,11 @@ import (
"github.com/spf13/cobra"
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service"
+ "github.com/spiral/roadrunner/service/watcher"
"os"
)
-// Service bus for all the commands.
+// Services bus for all the commands.
var (
cfgFile, workDir, logFormat string
override []string
@@ -106,6 +107,14 @@ func init() {
util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
os.Exit(1)
}
+
+ // global watcher config
+ wcv, _ := Container.Get(watcher.ID)
+ if wcv, ok := wcv.(*watcher.Service); ok {
+ wcv.AddListener(func(event int, ctx interface{}) {
+ util.LogEvent(Logger, event, ctx)
+ })
+ }
})
}
diff --git a/cmd/rr/main.go b/cmd/rr/main.go
index 54915957..dc2fbc20 100644
--- a/cmd/rr/main.go
+++ b/cmd/rr/main.go
@@ -24,6 +24,7 @@ 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"
@@ -40,6 +41,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{})
// you can register additional commands using cmd.CLI
rr.Execute()
diff --git a/cmd/util/debug.go b/cmd/util/debug.go
index f64b9bc4..54ef104f 100644
--- a/cmd/util/debug.go
+++ b/cmd/util/debug.go
@@ -3,6 +3,7 @@ package util
import (
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
+ "github.com/spiral/roadrunner/service/watcher"
"strings"
)
@@ -12,7 +13,7 @@ func LogEvent(logger *logrus.Logger, event int, ctx interface{}) bool {
case roadrunner.EventWorkerKill:
w := ctx.(*roadrunner.Worker)
logger.Warning(Sprintf(
- "<white+hb>worker.%v</reset> <yellow>killed</red>",
+ "<white+hb>worker.%v</reset> <yellow>killed</reset>",
*w.Pid,
))
return true
@@ -57,5 +58,26 @@ 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.EventMaxMemory:
+ w := ctx.(roadrunner.WorkerError)
+ logger.Warning(Sprintf(
+ "<white+hb>worker.%v</reset> <red>%s</reset>",
+ *w.Worker.Pid,
+ w.Caused,
+ ))
+ return true
+ }
+
return false
}