summaryrefslogtreecommitdiff
path: root/service/limit
diff options
context:
space:
mode:
Diffstat (limited to 'service/limit')
-rw-r--r--service/limit/config.go2
-rw-r--r--service/limit/config_test.go20
-rw-r--r--service/limit/controller.go2
-rw-r--r--service/limit/service.go14
4 files changed, 29 insertions, 9 deletions
diff --git a/service/limit/config.go b/service/limit/config.go
index bf842ac2..203db11b 100644
--- a/service/limit/config.go
+++ b/service/limit/config.go
@@ -6,7 +6,7 @@ import (
"time"
)
-// Configures set of Services.
+// Config of Limit service.
type Config struct {
// Interval defines the update duration for underlying controllers, default 1s.
Interval time.Duration
diff --git a/service/limit/config_test.go b/service/limit/config_test.go
new file mode 100644
index 00000000..aa793623
--- /dev/null
+++ b/service/limit/config_test.go
@@ -0,0 +1,20 @@
+package limit
+
+import (
+ "encoding/json"
+ "github.com/spiral/roadrunner/service"
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+type mockCfg struct{ cfg string }
+
+func (cfg *mockCfg) Get(name string) service.Config { return nil }
+func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }
+
+func Test_Config_Hydrate_Error1(t *testing.T) {
+ cfg := &mockCfg{`{"enable": true}`}
+ c := &Config{}
+
+ assert.Error(t, c.Hydrate(cfg))
+}
diff --git a/service/limit/controller.go b/service/limit/controller.go
index bdbab003..3e6aed4b 100644
--- a/service/limit/controller.go
+++ b/service/limit/controller.go
@@ -17,7 +17,7 @@ const (
// EventMaxIdleTTL triggered when worker spends too much time at rest.
EventMaxIdleTTL
- // EventMaxIdleTTL triggered when worker spends too much time doing the task (max_execution_time).
+ // EventMaxExecTTL triggered when worker spends too much time doing the task (max_execution_time).
EventMaxExecTTL
)
diff --git a/service/limit/service.go b/service/limit/service.go
index 72673d1f..99e2b1ee 100644
--- a/service/limit/service.go
+++ b/service/limit/service.go
@@ -8,13 +8,13 @@ import (
// ID defines controller service name.
const ID = "constrain"
-// Controllable defines the ability to attach rr controller.
-type Controllable interface {
- // AddController attaches controller to the service.
- AddController(c roadrunner.Controller)
+// controllable defines the ability to attach rr controller.
+type controllable interface {
+ // Attach attaches controller to the service.
+ Attach(c roadrunner.Controller)
}
-// Services to control the state of rr service inside other services.
+// Service to control the state of rr service inside other services.
type Service struct {
cfg *Config
lsns []func(event int, ctx interface{})
@@ -25,8 +25,8 @@ func (s *Service) Init(cfg *Config, c service.Container) (bool, error) {
// mount Services to designated services
for id, watcher := range cfg.Controllers(s.throw) {
svc, _ := c.Get(id)
- if ctrl, ok := svc.(Controllable); ok {
- ctrl.AddController(watcher)
+ if ctrl, ok := svc.(controllable); ok {
+ ctrl.Attach(watcher)
}
}