mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix(plugins): align watcher lifecycle with startup (#6366)
This commit is contained in:
@@ -275,10 +275,6 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
"plugins",
|
||||
self.resolve_event_handler_instance,
|
||||
)
|
||||
# 开发者模式监测插件修改
|
||||
if settings.DEV or settings.PLUGIN_AUTO_RELOAD:
|
||||
self.__start_monitor()
|
||||
|
||||
def resolve_event_handler_instance(
|
||||
self,
|
||||
owner_class: Type[Any],
|
||||
@@ -387,6 +383,11 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
"""返回配置重载日志使用的功能名称。"""
|
||||
return "插件文件修改监测"
|
||||
|
||||
def start_monitor(self):
|
||||
"""按当前配置启动插件文件修改监测。"""
|
||||
if settings.DEV or settings.PLUGIN_AUTO_RELOAD:
|
||||
self._plugin_monitor.start()
|
||||
|
||||
def reload_monitor(self):
|
||||
"""
|
||||
重新加载插件文件修改监测
|
||||
@@ -395,12 +396,6 @@ class PluginManager(ConfigReloadMixin, metaclass=Singleton):
|
||||
enabled=settings.DEV or settings.PLUGIN_AUTO_RELOAD
|
||||
)
|
||||
|
||||
def __start_monitor(self):
|
||||
"""
|
||||
启用监测插件文件修改监测
|
||||
"""
|
||||
self._plugin_monitor.start()
|
||||
|
||||
def stop_monitor(self):
|
||||
"""
|
||||
停止监测插件文件修改监测
|
||||
|
||||
@@ -5,6 +5,7 @@ from app.runtime.compat.diagnostics import (
|
||||
scan_plugin_legacy_imports,
|
||||
)
|
||||
from app.runtime.compat.resource_imports import scan_plugin_resource_imports
|
||||
from app.application.plugin.routes import register_plugin_api
|
||||
from app.runtime.config import global_vars
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.extensions.plugin_manager import (
|
||||
@@ -162,21 +163,15 @@ async def execute_task(loop, task_func, task_name):
|
||||
return []
|
||||
|
||||
|
||||
def register_plugin_api():
|
||||
"""
|
||||
插件启动后注册插件API
|
||||
"""
|
||||
from app.api.endpoints import plugin
|
||||
plugin.register_plugin_api()
|
||||
|
||||
|
||||
def init_plugins():
|
||||
"""
|
||||
初始化插件
|
||||
"""
|
||||
configure_plugin_services()
|
||||
PluginManager().start()
|
||||
plugin_manager = PluginManager()
|
||||
plugin_manager.start()
|
||||
register_plugin_api()
|
||||
plugin_manager.start_monitor()
|
||||
|
||||
|
||||
def stop_plugins():
|
||||
@@ -185,7 +180,9 @@ def stop_plugins():
|
||||
"""
|
||||
try:
|
||||
plugin_manager = PluginManager()
|
||||
plugin_manager.stop()
|
||||
plugin_manager.stop_monitor()
|
||||
try:
|
||||
plugin_manager.stop_monitor()
|
||||
finally:
|
||||
plugin_manager.stop()
|
||||
except Exception as e:
|
||||
logger.error(f"停止插件时发生错误:{e}", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user