diff options
author | Valery Piashchynski <[email protected]> | 2021-08-17 19:55:15 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-08-17 19:55:15 +0300 |
commit | ab690ab9c6ae2b00aef1b501e8b17ff02b5da753 (patch) | |
tree | 0a58b043605ef1d9b09e75b207c236aacb1ed55a /plugins/informer | |
parent | bd0da830ae345e1ed4a67782bf413673beeba037 (diff) |
Update to go 1.17
Add Stat with tests
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/informer')
-rw-r--r-- | plugins/informer/plugin.go | 34 | ||||
-rw-r--r-- | plugins/informer/rpc.go | 9 |
2 files changed, 40 insertions, 3 deletions
diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go index 21fd7983..87180be5 100644 --- a/plugins/informer/plugin.go +++ b/plugins/informer/plugin.go @@ -1,20 +1,30 @@ package informer import ( + "context" + endure "github.com/spiral/endure/pkg/container" + "github.com/spiral/roadrunner/v2/pkg/state/job" "github.com/spiral/roadrunner/v2/pkg/state/process" + "github.com/spiral/roadrunner/v2/plugins/logger" ) const PluginName = "informer" type Plugin struct { + log logger.Logger + + withJobs map[string]JobsStat withWorkers map[string]Informer available map[string]Availabler } -func (p *Plugin) Init() error { +func (p *Plugin) Init(log logger.Logger) error { p.available = make(map[string]Availabler) p.withWorkers = make(map[string]Informer) + p.withJobs = make(map[string]JobsStat) + + p.log = log return nil } @@ -28,11 +38,29 @@ func (p *Plugin) Workers(name string) []*process.State { return svc.Workers() } +// Jobs provides information about jobs for the registered plugin using jobs +func (p *Plugin) Jobs(name string) []*job.State { + svc, ok := p.withJobs[name] + if !ok { + return nil + } + + st, err := svc.JobsState(context.Background()) + if err != nil { + p.log.Info("jobs stat", "error", err) + // skip errors here + return nil + } + + return st +} + // Collects declares services to be collected. func (p *Plugin) Collects() []interface{} { return []interface{}{ p.CollectPlugins, p.CollectWorkers, + p.CollectJobs, } } @@ -46,6 +74,10 @@ func (p *Plugin) CollectWorkers(name endure.Named, r Informer) { p.withWorkers[name.Name()] = r } +func (p *Plugin) CollectJobs(name endure.Named, j JobsStat) { + p.withJobs[name.Name()] = j +} + // Name of the service. func (p *Plugin) Name() string { return PluginName diff --git a/plugins/informer/rpc.go b/plugins/informer/rpc.go index 3738b619..478d3227 100644 --- a/plugins/informer/rpc.go +++ b/plugins/informer/rpc.go @@ -1,6 +1,7 @@ package informer import ( + "github.com/spiral/roadrunner/v2/pkg/state/job" "github.com/spiral/roadrunner/v2/pkg/state/process" ) @@ -10,7 +11,7 @@ type rpc struct { // WorkerList contains list of workers. type WorkerList struct { - // Workers is list of workers. + // Workers are list of workers. Workers []*process.State `json:"workers"` } @@ -29,7 +30,6 @@ func (rpc *rpc) List(_ bool, list *[]string) error { func (rpc *rpc) Workers(service string, list *WorkerList) error { workers := rpc.srv.Workers(service) if workers == nil { - list = nil return nil } @@ -39,6 +39,11 @@ func (rpc *rpc) Workers(service string, list *WorkerList) error { return nil } +func (rpc *rpc) Jobs(service string, out *[]*job.State) error { + *out = rpc.srv.Jobs(service) + return nil +} + // sort.Sort func (w *WorkerList) Len() int { |