模块管理种新增根据模块id精确获取模块的方法,以便在插件等场景精确获取qb/tr等由系统统一维护的模块,而不需要插件各自为政

This commit is contained in:
Allen 2024-05-27 10:09:18 +08:00
parent b238c6ad11
commit bacb7aaeb4

View File

@ -1,5 +1,5 @@
import traceback import traceback
from typing import Generator, Optional, Tuple from typing import Generator, Optional, Tuple, Any
from app.core.config import settings from app.core.config import settings
from app.helper.module import ModuleHelper from app.helper.module import ModuleHelper
@ -97,6 +97,16 @@ class ModuleManager(metaclass=Singleton):
return True return True
return False return False
def get_running_module(self, module_id: str) -> Any:
"""
根据模块id获取模块运行实例
"""
if not module_id:
return None
if not self._running_modules:
return None
return self._running_modules.get(module_id)
def get_running_modules(self, method: str) -> Generator: def get_running_modules(self, method: str) -> Generator:
""" """
获取实现了同一方法的模块列表 获取实现了同一方法的模块列表
@ -108,6 +118,16 @@ class ModuleManager(metaclass=Singleton):
and ObjectUtils.check_method(getattr(module, method)): and ObjectUtils.check_method(getattr(module, method)):
yield module yield module
def get_module(self, module_id: str) -> Any:
"""
根据模块id获取模块
"""
if not module_id:
return None
if not self._modules:
return None
return self._modules.get(module_id)
def get_modules(self) -> dict: def get_modules(self) -> dict:
""" """
获取模块列表 获取模块列表