From bacb7aaeb474f8ca907401e6defe08ec9b84abe8 Mon Sep 17 00:00:00 2001 From: Allen Date: Mon, 27 May 2024 10:09:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=AE=A1=E7=90=86=E7=A7=8D?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=B9=E6=8D=AE=E6=A8=A1=E5=9D=97id?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE=E8=8E=B7=E5=8F=96=E6=A8=A1=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BB=A5=E4=BE=BF=E5=9C=A8=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=AD=89=E5=9C=BA=E6=99=AF=E7=B2=BE=E7=A1=AE=E8=8E=B7?= =?UTF-8?q?=E5=8F=96qb/tr=E7=AD=89=E7=94=B1=E7=B3=BB=E7=BB=9F=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=BB=B4=E6=8A=A4=E7=9A=84=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E9=9C=80=E8=A6=81=E6=8F=92=E4=BB=B6=E5=90=84?= =?UTF-8?q?=E8=87=AA=E4=B8=BA=E6=94=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/module.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/core/module.py b/app/core/module.py index bb397e53..23489fde 100644 --- a/app/core/module.py +++ b/app/core/module.py @@ -1,5 +1,5 @@ import traceback -from typing import Generator, Optional, Tuple +from typing import Generator, Optional, Tuple, Any from app.core.config import settings from app.helper.module import ModuleHelper @@ -97,6 +97,16 @@ class ModuleManager(metaclass=Singleton): return True 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: """ 获取实现了同一方法的模块列表 @@ -108,6 +118,16 @@ class ModuleManager(metaclass=Singleton): and ObjectUtils.check_method(getattr(module, method)): 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: """ 获取模块列表