From e200b70ea6636cdce08cf7662804d7c3b60bcbb5 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 25 Dec 2025 18:56:34 -0500 Subject: [PATCH] refactor: rename pluginInstance to plugin for consistency across the codebase Signed-off-by: Deluan --- plugins/capability_lifecycle.go | 2 +- plugins/host_scheduler_test.go | 2 +- plugins/host_subsonicapi_test.go | 4 +- plugins/host_websocket.go | 2 +- plugins/host_websocket_test.go | 2 +- plugins/manager.go | 64 ++++++++++++++--------------- plugins/metadata_agent.go | 2 +- plugins/plugins_suite_test.go | 2 +- plugins/scrobbler_adapter.go | 2 +- plugins/watcher_integration_test.go | 2 +- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/plugins/capability_lifecycle.go b/plugins/capability_lifecycle.go index 3f15a41aa..1ab0b268d 100644 --- a/plugins/capability_lifecycle.go +++ b/plugins/capability_lifecycle.go @@ -29,7 +29,7 @@ type onInitOutput struct { // callPluginInit calls the plugin's nd_on_init function if it has the Lifecycle capability. // This is called after the plugin is fully loaded with all services registered. -func callPluginInit(ctx context.Context, instance *pluginInstance) { +func callPluginInit(ctx context.Context, instance *plugin) { if !hasCapability(instance.capabilities, CapabilityLifecycle) { return } diff --git a/plugins/host_scheduler_test.go b/plugins/host_scheduler_test.go index 5880ceb85..1cce3a214 100644 --- a/plugins/host_scheduler_test.go +++ b/plugins/host_scheduler_test.go @@ -56,7 +56,7 @@ var _ = Describe("SchedulerService", Ordered, func() { // Create and start manager manager = &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } err = manager.Start(GinkgoT().Context()) Expect(err).ToNot(HaveOccurred()) diff --git a/plugins/host_subsonicapi_test.go b/plugins/host_subsonicapi_test.go index e1455ea63..26ecabfc9 100644 --- a/plugins/host_subsonicapi_test.go +++ b/plugins/host_subsonicapi_test.go @@ -64,7 +64,7 @@ var _ = Describe("SubsonicAPI Host Function", Ordered, func() { // Create and configure manager manager = &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } manager.SetSubsonicRouter(router) manager.SetDataStore(dataStore) @@ -100,7 +100,7 @@ var _ = Describe("SubsonicAPI Host Function", Ordered, func() { }) Describe("SubsonicAPI Call", func() { - var plugin *pluginInstance + var plugin *plugin BeforeEach(func() { manager.mu.RLock() diff --git a/plugins/host_websocket.go b/plugins/host_websocket.go index 011be810b..78e4074fc 100644 --- a/plugins/host_websocket.go +++ b/plugins/host_websocket.go @@ -427,7 +427,7 @@ func (s *webSocketServiceImpl) invokeOnClose(ctx context.Context, connectionID s } } -func (s *webSocketServiceImpl) getPluginInstance() *pluginInstance { +func (s *webSocketServiceImpl) getPluginInstance() *plugin { s.manager.mu.RLock() instance, ok := s.manager.plugins[s.pluginName] s.manager.mu.RUnlock() diff --git a/plugins/host_websocket_test.go b/plugins/host_websocket_test.go index a666ba43e..5763fc556 100644 --- a/plugins/host_websocket_test.go +++ b/plugins/host_websocket_test.go @@ -49,7 +49,7 @@ var _ = Describe("WebSocketService", Ordered, func() { // Create and start manager manager = &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } err = manager.Start(GinkgoT().Context()) Expect(err).ToNot(HaveOccurred()) diff --git a/plugins/manager.go b/plugins/manager.go index 76ffc125a..4d832b872 100644 --- a/plugins/manager.go +++ b/plugins/manager.go @@ -44,7 +44,7 @@ type SubsonicRouter = http.Handler // It implements both agents.PluginLoader and scrobbler.PluginLoader interfaces. type Manager struct { mu sync.RWMutex - plugins map[string]*pluginInstance + plugins map[string]*plugin ctx context.Context cancel context.CancelFunc cache wazero.CompilationCache @@ -62,8 +62,8 @@ type Manager struct { ds model.DataStore } -// pluginInstance represents a loaded plugin -type pluginInstance struct { +// plugin represents a loaded plugin +type plugin struct { name string // Plugin name (from filename) path string // Path to the wasm file manifest *Manifest @@ -72,18 +72,18 @@ type pluginInstance struct { closers []io.Closer // Cleanup functions to call on unload } -func (p *pluginInstance) instance() (*extism.Plugin, error) { - plugin, err := p.compiled.Instance(context.Background(), extism.PluginInstanceConfig{ +func (p *plugin) instance() (*extism.Plugin, error) { + instance, err := p.compiled.Instance(context.Background(), extism.PluginInstanceConfig{ ModuleConfig: wazero.NewModuleConfig().WithSysWalltime().WithRandSource(rand.Reader), }) if err != nil { return nil, err } - plugin.SetLogger(extismLogger(p.name)) - return plugin, nil + instance.SetLogger(extismLogger(p.name)) + return instance, nil } -func (p *pluginInstance) Close() error { +func (p *plugin) Close() error { var errs []error for _, f := range p.closers { err := f.Close() @@ -99,7 +99,7 @@ func (p *pluginInstance) Close() error { func GetManager() *Manager { return singleton.GetInstance(func() *Manager { return &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } }) } @@ -194,14 +194,14 @@ func (m *Manager) Stop() error { defer m.mu.Unlock() // Close all plugins - for name, instance := range m.plugins { - if instance.compiled != nil { - if err := instance.compiled.Close(context.Background()); err != nil { + for name, plugin := range m.plugins { + if plugin.compiled != nil { + if err := plugin.compiled.Close(context.Background()); err != nil { log.Error("Error closing plugin", "plugin", name, err) } } } - m.plugins = make(map[string]*pluginInstance) + m.plugins = make(map[string]*plugin) // Close compilation cache if m.cache != nil { @@ -223,8 +223,8 @@ func (m *Manager) PluginNames(capability string) []string { var names []string cap := Capability(capability) - for name, instance := range m.plugins { - if hasCapability(instance.capabilities, cap) { + for name, plugin := range m.plugins { + if hasCapability(plugin.capabilities, cap) { names = append(names, name) } } @@ -235,17 +235,17 @@ func (m *Manager) PluginNames(capability string) []string { // Returns false if the plugin is not found or doesn't have the MetadataAgent capability. func (m *Manager) LoadMediaAgent(name string) (agents.Interface, bool) { m.mu.RLock() - instance, ok := m.plugins[name] + plugin, ok := m.plugins[name] m.mu.RUnlock() - if !ok || !hasCapability(instance.capabilities, CapabilityMetadataAgent) { + if !ok || !hasCapability(plugin.capabilities, CapabilityMetadataAgent) { return nil, false } // Create a new metadata agent adapter for this plugin return &MetadataAgent{ - name: instance.name, - plugin: instance, + name: plugin.name, + plugin: plugin, }, true } @@ -253,17 +253,17 @@ func (m *Manager) LoadMediaAgent(name string) (agents.Interface, bool) { // Returns false if the plugin is not found or doesn't have the Scrobbler capability. func (m *Manager) LoadScrobbler(name string) (scrobbler.Scrobbler, bool) { m.mu.RLock() - instance, ok := m.plugins[name] + plugin, ok := m.plugins[name] m.mu.RUnlock() - if !ok || !hasCapability(instance.capabilities, CapabilityScrobbler) { + if !ok || !hasCapability(plugin.capabilities, CapabilityScrobbler) { return nil, false } // Create a new scrobbler adapter for this plugin return &ScrobblerPlugin{ - name: instance.name, - plugin: instance, + name: plugin.name, + plugin: plugin, }, true } @@ -279,10 +279,10 @@ func (m *Manager) GetPluginInfo() map[string]PluginInfo { defer m.mu.RUnlock() info := make(map[string]PluginInfo, len(m.plugins)) - for name, instance := range m.plugins { + for name, plugin := range m.plugins { info[name] = PluginInfo{ - Name: instance.manifest.Name, - Version: instance.manifest.Version, + Name: plugin.manifest.Name, + Version: plugin.manifest.Version, } } return info @@ -442,7 +442,7 @@ func (m *Manager) loadPlugin(name, wasmPath string) error { } m.mu.Lock() - m.plugins[name] = &pluginInstance{ + m.plugins[name] = &plugin{ name: name, path: wasmPath, manifest: &manifest, @@ -470,7 +470,7 @@ func (m *Manager) getPluginConfig(name string) map[string]string { // Returns an error if the plugin is not found. func (m *Manager) UnloadPlugin(name string) error { m.mu.Lock() - instance, ok := m.plugins[name] + plugin, ok := m.plugins[name] if !ok { m.mu.Unlock() return fmt.Errorf("plugin %q not found", name) @@ -479,18 +479,18 @@ func (m *Manager) UnloadPlugin(name string) error { m.mu.Unlock() // Run cleanup functions - err := instance.Close() + err := plugin.Close() if err != nil { log.Error("Error during plugin cleanup", "plugin", name, err) } // Close the compiled plugin outside the lock with a grace period // to allow in-flight requests to complete - if instance.compiled != nil { + if plugin.compiled != nil { // Use a brief timeout for cleanup ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - if err := instance.compiled.Close(ctx); err != nil { + if err := plugin.compiled.Close(ctx); err != nil { log.Error("Error closing plugin during unload", "plugin", name, err) } } @@ -551,7 +551,7 @@ var errFunctionNotFound = errors.New("function not found") // callPluginFunction is a helper to call a plugin function with input and output types. // It handles JSON marshalling/unmarshalling and error checking. -func callPluginFunction[I any, O any](ctx context.Context, plugin *pluginInstance, funcName string, input I) (O, error) { +func callPluginFunction[I any, O any](ctx context.Context, plugin *plugin, funcName string, input I) (O, error) { start := time.Now() var result O diff --git a/plugins/metadata_agent.go b/plugins/metadata_agent.go index 05aed70de..84bf32067 100644 --- a/plugins/metadata_agent.go +++ b/plugins/metadata_agent.go @@ -41,7 +41,7 @@ func init() { // the agents interfaces for metadata retrieval. type MetadataAgent struct { name string - plugin *pluginInstance + plugin *plugin } // AgentName returns the plugin name diff --git a/plugins/plugins_suite_test.go b/plugins/plugins_suite_test.go index 38799bf3f..983a3a443 100644 --- a/plugins/plugins_suite_test.go +++ b/plugins/plugins_suite_test.go @@ -80,7 +80,7 @@ func createTestManagerWithPlugins(pluginConfig map[string]map[string]string, plu // Create and start manager manager := &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } err = manager.Start(GinkgoT().Context()) Expect(err).ToNot(HaveOccurred()) diff --git a/plugins/scrobbler_adapter.go b/plugins/scrobbler_adapter.go index 9bb7a6abe..bc5603c12 100644 --- a/plugins/scrobbler_adapter.go +++ b/plugins/scrobbler_adapter.go @@ -33,7 +33,7 @@ func init() { // the scrobbler.Scrobbler interface for scrobbling to external services. type ScrobblerPlugin struct { name string - plugin *pluginInstance + plugin *plugin } // IsAuthorized checks if the user is authorized with this scrobbler diff --git a/plugins/watcher_integration_test.go b/plugins/watcher_integration_test.go index 15bb102a0..aaa52fb1c 100644 --- a/plugins/watcher_integration_test.go +++ b/plugins/watcher_integration_test.go @@ -89,7 +89,7 @@ var _ = Describe("Watcher Integration", Ordered, func() { conf.Server.Plugins.AutoReload = true autoReloadManager := &Manager{ - plugins: make(map[string]*pluginInstance), + plugins: make(map[string]*plugin), } err := autoReloadManager.Start(ctx) Expect(err).ToNot(HaveOccurred())