Plugins: Remove registry dependency from process manager (#73241)

simplify
This commit is contained in:
Will Browne
2023-08-16 10:46:00 +02:00
committed by GitHub
parent d935e6ff57
commit 75b0788377
16 changed files with 202 additions and 221 deletions

View File

@ -10,6 +10,7 @@ import (
"path"
"runtime"
"strings"
"sync"
"github.com/grafana/grafana-plugin-sdk-go/backend"
@ -62,6 +63,8 @@ type Plugin struct {
client backendplugin.Plugin
log log.Logger
mu sync.Mutex
// This will be moved to plugin.json when we have general support in gcom
Alias string `json:"alias,omitempty"`
}
@ -264,16 +267,24 @@ func (p *Plugin) SetLogger(l log.Logger) {
}
func (p *Plugin) Start(ctx context.Context) error {
p.mu.Lock()
defer p.mu.Unlock()
if p.client == nil {
return fmt.Errorf("could not start plugin %s as no plugin client exists", p.ID)
}
return p.client.Start(ctx)
}
func (p *Plugin) Stop(ctx context.Context) error {
p.mu.Lock()
defer p.mu.Unlock()
if p.client == nil {
return nil
}
return p.client.Stop(ctx)
}
@ -285,6 +296,9 @@ func (p *Plugin) IsManaged() bool {
}
func (p *Plugin) Decommission() error {
p.mu.Lock()
defer p.mu.Unlock()
if p.client != nil {
return p.client.Decommission()
}