summaryrefslogtreecommitdiff
path: root/plugins/informer
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-30 16:30:54 +0300
committerGitHub <[email protected]>2021-04-30 16:30:54 +0300
commit009b7009885d8a15e6fa6c7e78436087b2f20129 (patch)
tree6bab1f99aa83c794060ab4c913d5ff62fef6882d /plugins/informer
parent684864530618f4b82399e5f1a89d5967c6ca9bcb (diff)
parent556477ca9df3fa2e5939057861314eabe5ce30ca (diff)
#652 feat(informer): list of active plugins in runtime
#652 feat(informer): list of active plugins in runtime
Diffstat (limited to 'plugins/informer')
-rw-r--r--plugins/informer/interface.go11
-rw-r--r--plugins/informer/plugin.go30
-rw-r--r--plugins/informer/rpc.go11
3 files changed, 30 insertions, 22 deletions
diff --git a/plugins/informer/interface.go b/plugins/informer/interface.go
index 45f44691..316c7bc1 100644
--- a/plugins/informer/interface.go
+++ b/plugins/informer/interface.go
@@ -4,7 +4,18 @@ import (
"github.com/spiral/roadrunner/v2/pkg/process"
)
+/*
+Informer plugin should not receive any other plugin in the Init or via Collects
+Because Availabler implementation should present in every plugin
+*/
+
// Informer used to get workers from particular plugin or set of plugins
type Informer interface {
Workers() []process.State
}
+
+// Availabler interface should be implemented by every plugin which wish to report to the PHP worker that it available in the RR runtime
+type Availabler interface {
+ // Available method needed to collect all plugins which are available in the runtime.
+ Available()
+}
diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go
index 98081d34..2d76123b 100644
--- a/plugins/informer/plugin.go
+++ b/plugins/informer/plugin.go
@@ -4,19 +4,18 @@ import (
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/pkg/process"
- "github.com/spiral/roadrunner/v2/plugins/logger"
)
const PluginName = "informer"
type Plugin struct {
- registry map[string]Informer
- log logger.Logger
+ registry map[string]Informer
+ available map[string]Availabler
}
-func (p *Plugin) Init(log logger.Logger) error {
+func (p *Plugin) Init() error {
+ p.available = make(map[string]Availabler)
p.registry = make(map[string]Informer)
- p.log = log
return nil
}
@@ -31,19 +30,24 @@ func (p *Plugin) Workers(name string) ([]process.State, error) {
return svc.Workers(), nil
}
-// CollectTarget resettable service.
-func (p *Plugin) CollectTarget(name endure.Named, r Informer) error {
- p.registry[name.Name()] = r
- return nil
-}
-
// Collects declares services to be collected.
func (p *Plugin) Collects() []interface{} {
return []interface{}{
- p.CollectTarget,
+ p.CollectPlugins,
+ p.CollectWorkers,
}
}
+// CollectPlugins collects all RR plugins
+func (p *Plugin) CollectPlugins(name endure.Named, l Availabler) {
+ p.available[name.Name()] = l
+}
+
+// CollectWorkers obtains plugins with workers inside.
+func (p *Plugin) CollectWorkers(name endure.Named, r Informer) {
+ p.registry[name.Name()] = r
+}
+
// Name of the service.
func (p *Plugin) Name() string {
return PluginName
@@ -51,5 +55,5 @@ func (p *Plugin) Name() string {
// 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/informer/rpc.go b/plugins/informer/rpc.go
index b0b5b1af..8955af92 100644
--- a/plugins/informer/rpc.go
+++ b/plugins/informer/rpc.go
@@ -2,12 +2,10 @@ package informer
import (
"github.com/spiral/roadrunner/v2/pkg/process"
- "github.com/spiral/roadrunner/v2/plugins/logger"
)
type rpc struct {
srv *Plugin
- log logger.Logger
}
// WorkerList contains list of workers.
@@ -18,20 +16,17 @@ type WorkerList struct {
// List all resettable services.
func (rpc *rpc) List(_ bool, list *[]string) error {
- rpc.log.Debug("Started List method")
*list = make([]string, 0, len(rpc.srv.registry))
- for name := range rpc.srv.registry {
+ // append all plugin names to the output result
+ for name := range rpc.srv.available {
*list = append(*list, name)
}
- rpc.log.Debug("list of services", "list", *list)
- rpc.log.Debug("successfully finished List method")
return nil
}
// Workers state of a given service.
func (rpc *rpc) Workers(service string, list *WorkerList) error {
- rpc.log.Debug("started Workers method", "service", service)
workers, err := rpc.srv.Workers(service)
if err != nil {
return err
@@ -40,7 +35,5 @@ func (rpc *rpc) Workers(service string, list *WorkerList) error {
// write actual processes
list.Workers = workers
- rpc.log.Debug("list of workers", "workers", list.Workers)
- rpc.log.Debug("successfully finished Workers method")
return nil
}