summaryrefslogtreecommitdiff
path: root/plugins/informer/plugin.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-18 11:24:20 +0300
committerValery Piashchynski <[email protected]>2020-11-18 11:24:20 +0300
commit2b395a5f1bd431a2a9c80c35a2ca5f42066c9ffd (patch)
tree1542b018ee2aa8511f5e8a8b64b2f45c52e91048 /plugins/informer/plugin.go
parenta2ba8de5eb519f73044a9b1c66f087a5b65e3d45 (diff)
parent0a48a027642a34c560717526c55f70b7260d678c (diff)
Merge branch 'release_2.0' into plugin/http
Diffstat (limited to 'plugins/informer/plugin.go')
-rw-r--r--plugins/informer/plugin.go56
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}
+}