feat:插件支持注册公共服务
This commit is contained in:
parent
0f57ec099a
commit
b06795510a
@ -213,6 +213,26 @@ class PluginManager(metaclass=Singleton):
|
|||||||
ret_apis.extend(apis)
|
ret_apis.extend(apis)
|
||||||
return ret_apis
|
return ret_apis
|
||||||
|
|
||||||
|
def get_plugin_services(self) -> List[Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
获取插件服务
|
||||||
|
[{
|
||||||
|
"id": "服务ID",
|
||||||
|
"name": "服务名称",
|
||||||
|
"trigger": "触发器:cron、interval、date、CronTrigger.from_crontab()",
|
||||||
|
"func": self.xxx,
|
||||||
|
"kwagrs": {} # 定时器参数
|
||||||
|
}]
|
||||||
|
"""
|
||||||
|
ret_services = []
|
||||||
|
for pid, plugin in self._running_plugins.items():
|
||||||
|
if hasattr(plugin, "get_service") \
|
||||||
|
and ObjectUtils.check_method(plugin.get_service):
|
||||||
|
services = plugin.get_service()
|
||||||
|
if services:
|
||||||
|
ret_services.extend(services)
|
||||||
|
return ret_services
|
||||||
|
|
||||||
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
def run_plugin_method(self, pid: str, method: str, *args, **kwargs) -> Any:
|
||||||
"""
|
"""
|
||||||
运行插件方法
|
运行插件方法
|
||||||
|
@ -57,7 +57,7 @@ class _PluginBase(metaclass=ABCMeta):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_command() -> List[Dict[str, Any]]:
|
def get_command() -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
获取插件命令
|
注册插件远程命令
|
||||||
[{
|
[{
|
||||||
"cmd": "/xx",
|
"cmd": "/xx",
|
||||||
"event": EventType.xx,
|
"event": EventType.xx,
|
||||||
@ -71,7 +71,7 @@ class _PluginBase(metaclass=ABCMeta):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_api(self) -> List[Dict[str, Any]]:
|
def get_api(self) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
获取插件API
|
注册插件API
|
||||||
[{
|
[{
|
||||||
"path": "/xx",
|
"path": "/xx",
|
||||||
"endpoint": self.xxx,
|
"endpoint": self.xxx,
|
||||||
@ -82,6 +82,19 @@ class _PluginBase(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_service(self) -> List[Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
注册插件公共服务
|
||||||
|
[{
|
||||||
|
“id”: “服务ID”,
|
||||||
|
"name": "服务名称",
|
||||||
|
"trigger": "触发器:cron/interval/date/CronTrigger.from_crontab()",
|
||||||
|
"func": self.xxx,
|
||||||
|
"kwargs": {} # 定时器参数
|
||||||
|
}]
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
|
@ -16,6 +16,7 @@ from app.chain.tmdb import TmdbChain
|
|||||||
from app.chain.torrents import TorrentsChain
|
from app.chain.torrents import TorrentsChain
|
||||||
from app.chain.transfer import TransferChain
|
from app.chain.transfer import TransferChain
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
from app.core.plugin import PluginManager
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.timer import TimerUtils
|
from app.utils.timer import TimerUtils
|
||||||
@ -227,6 +228,27 @@ class Scheduler(metaclass=Singleton):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 注册插件公共服务
|
||||||
|
plugin_services = PluginManager().get_plugin_services()
|
||||||
|
for service in plugin_services:
|
||||||
|
try:
|
||||||
|
self._jobs[service["id"]] = {
|
||||||
|
"func": service["func"],
|
||||||
|
"running": False,
|
||||||
|
}
|
||||||
|
self._scheduler.add_job(
|
||||||
|
self.start,
|
||||||
|
service["trigger"],
|
||||||
|
id=service["id"],
|
||||||
|
name=service["name"],
|
||||||
|
**service["kwargs"],
|
||||||
|
kwargs={
|
||||||
|
'job_id': service["id"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"注册插件服务失败:{str(e)} - {service}")
|
||||||
|
|
||||||
# 打印服务
|
# 打印服务
|
||||||
logger.debug(self._scheduler.print_jobs())
|
logger.debug(self._scheduler.print_jobs())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user