summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-08-17 23:27:37 +0300
committerValery Piashchynski <[email protected]>2021-08-17 23:27:37 +0300
commit65a70f5d15fb0a1b1f787ff7f06b3a299dab0f96 (patch)
treec6c3e8f4b5952c4e389804da38fea0e03b2cd111 /plugins
parent064d375e3671135226cb3bc70be057339b23f26f (diff)
Update Resetter plugin, remove old and unused code
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/gzip/plugin.go1
-rw-r--r--plugins/reload/plugin.go16
-rw-r--r--plugins/resetter/interface.go16
-rw-r--r--plugins/resetter/plugin.go43
-rw-r--r--plugins/resetter/rpc.go17
5 files changed, 26 insertions, 67 deletions
diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go
index a957878c..05f1eb63 100644
--- a/plugins/gzip/plugin.go
+++ b/plugins/gzip/plugin.go
@@ -10,7 +10,6 @@ const PluginName = "gzip"
type Plugin struct{}
-// Init needed for the Endure
func (g *Plugin) Init() error {
return nil
}
diff --git a/plugins/reload/plugin.go b/plugins/reload/plugin.go
index d3271d6c..a9a5a63c 100644
--- a/plugins/reload/plugin.go
+++ b/plugins/reload/plugin.go
@@ -20,12 +20,12 @@ type Plugin struct {
log logger.Logger
watcher *Watcher
services map[string]interface{}
- res resetter.Resetter
+ res *resetter.Plugin
stopc chan struct{}
}
// Init controller service
-func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, res resetter.Resetter) error {
+func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, res *resetter.Plugin) error {
const op = errors.Op("reload_plugin_init")
if !cfg.Has(PluginName) {
return errors.E(op, errors.Disabled)
@@ -86,9 +86,9 @@ func (s *Plugin) Serve() chan error {
}
// make a map with unique services
- // so, if we would have a 100 events from http service
- // in map we would see only 1 key and it's config
- treshholdc := make(chan struct {
+ // so, if we would have 100 events from http service
+ // in map we would see only 1 key, and it's config
+ thCh := make(chan struct {
serviceConfig ServiceConfig
service string
}, thresholdChanBuffer)
@@ -98,7 +98,7 @@ func (s *Plugin) Serve() chan error {
go func() {
for e := range s.watcher.Event {
- treshholdc <- struct {
+ thCh <- struct {
serviceConfig ServiceConfig
service string
}{serviceConfig: s.cfg.Services[e.service], service: e.service}
@@ -111,7 +111,7 @@ func (s *Plugin) Serve() chan error {
go func() {
for {
select {
- case cfg := <-treshholdc:
+ case cfg := <-thCh:
// logic is following:
// restart
timer.Stop()
@@ -124,7 +124,7 @@ func (s *Plugin) Serve() chan error {
case <-timer.C:
if len(updated) > 0 {
for name := range updated {
- err := s.res.ResetByName(name)
+ err := s.res.Reset(name)
if err != nil {
timer.Stop()
errCh <- errors.E(op, err)
diff --git a/plugins/resetter/interface.go b/plugins/resetter/interface.go
index 47d8d791..0defcaba 100644
--- a/plugins/resetter/interface.go
+++ b/plugins/resetter/interface.go
@@ -1,17 +1,7 @@
package resetter
-// If plugin implements Resettable interface, than it state can be resetted without reload in runtime via RPC/HTTP
-type Resettable interface {
- // Reset reload all plugins
- Reset() error
-}
-
-// Resetter interface is the Resetter plugin main interface
+// Resetter interface
type Resetter interface {
- // Reset all registered plugins
- ResetAll() error
- // Reset by plugin name
- ResetByName(string) error
- // GetAll registered plugins
- GetAll() []string
+ // Reset reload plugin
+ Reset() error
}
diff --git a/plugins/resetter/plugin.go b/plugins/resetter/plugin.go
index 4feb692a..b2fe59af 100644
--- a/plugins/resetter/plugin.go
+++ b/plugins/resetter/plugin.go
@@ -3,61 +3,32 @@ package resetter
import (
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
- "github.com/spiral/roadrunner/v2/plugins/logger"
)
const PluginName = "resetter"
type Plugin struct {
- registry map[string]Resettable
- log logger.Logger
+ registry map[string]Resetter
}
-func (p *Plugin) ResetAll() error {
- const op = errors.Op("resetter_plugin_reset_all")
- for name := range p.registry {
- err := p.registry[name].Reset()
- if err != nil {
- return errors.E(op, err)
- }
- }
- return nil
-}
-
-func (p *Plugin) ResetByName(plugin string) error {
- const op = errors.Op("resetter_plugin_reset_by_name")
- if plugin, ok := p.registry[plugin]; ok {
- return plugin.Reset()
- }
- return errors.E(op, errors.Errorf("can't find plugin: %s", plugin))
-}
-
-func (p *Plugin) GetAll() []string {
- all := make([]string, 0, len(p.registry))
- for name := range p.registry {
- all = append(all, name)
- }
- return all
-}
-
-func (p *Plugin) Init(log logger.Logger) error {
- p.registry = make(map[string]Resettable)
- p.log = log
+func (p *Plugin) Init() error {
+ p.registry = make(map[string]Resetter)
return nil
}
// Reset named service.
func (p *Plugin) Reset(name string) error {
+ const op = errors.Op("resetter_plugin_reset_by_name")
svc, ok := p.registry[name]
if !ok {
- return errors.E("no such service", errors.Str(name))
+ return errors.E(op, errors.Errorf("no such service: %s", name))
}
return svc.Reset()
}
// RegisterTarget resettable service.
-func (p *Plugin) RegisterTarget(name endure.Named, r Resettable) error {
+func (p *Plugin) RegisterTarget(name endure.Named, r Resetter) error {
p.registry[name.Name()] = r
return nil
}
@@ -80,5 +51,5 @@ func (p *Plugin) Available() {
// RPC returns associated rpc service.
func (p *Plugin) RPC() interface{} {
- return &rpc{srv: p, log: p.log}
+ return &rpc{srv: p}
}
diff --git a/plugins/resetter/rpc.go b/plugins/resetter/rpc.go
index 69c955b0..79171b5c 100644
--- a/plugins/resetter/rpc.go
+++ b/plugins/resetter/rpc.go
@@ -1,30 +1,29 @@
package resetter
-import "github.com/spiral/roadrunner/v2/plugins/logger"
+import "github.com/spiral/errors"
type rpc struct {
srv *Plugin
- log logger.Logger
}
// List all resettable plugins.
func (rpc *rpc) List(_ bool, list *[]string) error {
- rpc.log.Debug("started List method")
*list = make([]string, 0)
for name := range rpc.srv.registry {
*list = append(*list, name)
}
- rpc.log.Debug("services list", "services", *list)
-
- rpc.log.Debug("finished List method")
return nil
}
// Reset named plugin.
func (rpc *rpc) Reset(service string, done *bool) error {
- rpc.log.Debug("started Reset method for the service", "service", service)
- defer rpc.log.Debug("finished Reset method for the service", "service", service)
+ const op = errors.Op("resetter_rpc_reset")
+ err := rpc.srv.Reset(service)
+ if err != nil {
+ *done = false
+ return errors.E(op, err)
+ }
*done = true
- return rpc.srv.Reset(service)
+ return nil
}