diff options
author | Valery Piashchynski <[email protected]> | 2021-04-30 11:44:07 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-04-30 11:44:07 +0300 |
commit | 50aa751dcefc0ab0e96594a5f111ead316a34a70 (patch) | |
tree | 5cf1fd278e01e1bd23a3f39d408ceb49741c448c /plugins/informer | |
parent | 65015a3d3f4b387675b5ca005b8831a6be9e15aa (diff) |
- Update Lister implementation
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/informer')
-rw-r--r-- | plugins/informer/interface.go | 13 | ||||
-rw-r--r-- | plugins/informer/plugin.go | 20 | ||||
-rw-r--r-- | plugins/informer/rpc.go | 11 |
3 files changed, 20 insertions, 24 deletions
diff --git a/plugins/informer/interface.go b/plugins/informer/interface.go index cd8ab232..08eda00b 100644 --- a/plugins/informer/interface.go +++ b/plugins/informer/interface.go @@ -4,13 +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 } -// Lister interface used to filter available plugins -type Lister interface { - // List gets no args, but returns list of the active plugins - List() []string +// 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 returns true if the particular plugin available in the RR2 runtime + Available() bool } diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go index 3d219cda..73e49575 100644 --- a/plugins/informer/plugin.go +++ b/plugins/informer/plugin.go @@ -4,20 +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 - plugins map[string]Lister - 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 } @@ -36,18 +34,18 @@ func (p *Plugin) Workers(name string) ([]process.State, error) { func (p *Plugin) Collects() []interface{} { return []interface{}{ p.CollectWorkers, + p.CollectPlugins, } } // CollectPlugins collects all RR plugins -func (p *Plugin) CollectPlugins(name endure.Named, l Lister) { - p.plugins[name.Name()] = l +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) error { +func (p *Plugin) CollectWorkers(name endure.Named, r Informer) { p.registry[name.Name()] = r - return nil } // Name of the service. @@ -57,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 } |