diff options
author | Valery Piashchynski <[email protected]> | 2020-11-18 10:37:44 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-11-18 10:37:44 +0300 |
commit | be18313f6bf8f903f2d2ba3ca812ad8546c329f6 (patch) | |
tree | 0a6d7382a526a59a034f85d60b3f2b24e103ffcd /plugins/informer/plugin.go | |
parent | 6236aac37bd1661b20400689f66d1e92283c5111 (diff) |
Informer plugin ready
Diffstat (limited to 'plugins/informer/plugin.go')
-rw-r--r-- | plugins/informer/plugin.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go new file mode 100644 index 00000000..09d933fd --- /dev/null +++ b/plugins/informer/plugin.go @@ -0,0 +1,56 @@ +package informer + +import ( + "github.com/spiral/endure" + "github.com/spiral/errors" + "github.com/spiral/roadrunner/v2" + "github.com/spiral/roadrunner/v2/interfaces/informer" + "github.com/spiral/roadrunner/v2/interfaces/log" +) + +const PluginName = "informer" + +type Plugin struct { + registry map[string]informer.Informer + log log.Logger +} + +func (p *Plugin) Init(log log.Logger) error { + p.registry = make(map[string]informer.Informer) + p.log = log + return nil +} + +// Reset named service. +func (p *Plugin) Workers(name string) ([]roadrunner.WorkerBase, error) { + const op = errors.Op("get workers") + svc, ok := p.registry[name] + if !ok { + return nil, errors.E(op, errors.Errorf("no such service: %s", name)) + } + + return svc.Workers(), nil +} + +// CollectTarget resettable service. +func (p *Plugin) CollectTarget(name endure.Named, r informer.Informer) error { + p.registry[name.Name()] = r + return nil +} + +// Collects declares services to be collected. +func (p *Plugin) Collects() []interface{} { + return []interface{}{ + p.CollectTarget, + } +} + +// Name of the service. +func (p *Plugin) Name() string { + return PluginName +} + +// RPCService returns associated rpc service. +func (p *Plugin) RPC() interface{} { + return &rpc{srv: p, log: p.log} +} |