Pārlūkot izejas kodu

feat: support auto gc of local plugin runtime

Yeuoly 8 mēneši atpakaļ
vecāks
revīzija
b3133676fc
1 mainītis faili ar 16 papildinājumiem un 1 dzēšanām
  1. 16 1
      internal/core/plugin_manager/watcher.go

+ 16 - 1
internal/core/plugin_manager/watcher.go

@@ -95,7 +95,22 @@ func (p *PluginManager) handleNewLocalPlugins() {
 
 // an async function to remove uninstalled local plugins
 func (p *PluginManager) removeUninstalledLocalPlugins() {
-	// TODO: implement
+	// read all local plugin runtimes
+	p.m.Range(func(key string, value plugin_entities.PluginLifetime) bool {
+		// try to convert to local runtime
+		runtime, ok := value.(*local_manager.LocalPluginRuntime)
+		if !ok {
+			return true
+		}
+
+		// check if plugin is deleted, stop it if so
+		plugin_path := filepath.Join(p.pluginStoragePath, key)
+		if _, err := os.Stat(plugin_path); os.IsNotExist(err) {
+			runtime.Stop()
+		}
+
+		return true
+	})
 }
 
 func (p *PluginManager) launchLocal(plugin_package_path string) (