mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-12 08:46:02 +00:00
feat: 完成异步任务跟踪架构基础
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import typing
|
||||
import abc
|
||||
|
||||
from ..core import app
|
||||
from ..core import app, taskmgr
|
||||
|
||||
|
||||
class PluginInstaller(metaclass=abc.ABCMeta):
|
||||
@@ -40,6 +40,7 @@ class PluginInstaller(metaclass=abc.ABCMeta):
|
||||
self,
|
||||
plugin_name: str,
|
||||
plugin_source: str=None,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""更新插件
|
||||
"""
|
||||
|
||||
@@ -9,6 +9,7 @@ import requests
|
||||
|
||||
from .. import installer, errors
|
||||
from ...utils import pkgmgr
|
||||
from ...core import taskmgr
|
||||
|
||||
|
||||
class GitHubRepoInstaller(installer.PluginInstaller):
|
||||
@@ -94,13 +95,20 @@ class GitHubRepoInstaller(installer.PluginInstaller):
|
||||
async def install_plugin(
|
||||
self,
|
||||
plugin_source: str,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""安装插件
|
||||
"""
|
||||
task_context.trace("下载插件源码...", "install-plugin")
|
||||
|
||||
repo_label = await self.download_plugin_source_code(plugin_source, "plugins/")
|
||||
|
||||
task_context.trace("安装插件依赖...", "install-plugin")
|
||||
|
||||
await self.install_requirements("plugins/" + repo_label)
|
||||
|
||||
task_context.trace("完成.", "install-plugin")
|
||||
|
||||
await self.ap.plugin_mgr.setting.record_installed_plugin_source(
|
||||
"plugins/"+repo_label+'/', plugin_source
|
||||
)
|
||||
@@ -122,9 +130,12 @@ class GitHubRepoInstaller(installer.PluginInstaller):
|
||||
self,
|
||||
plugin_name: str,
|
||||
plugin_source: str=None,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""更新插件
|
||||
"""
|
||||
task_context.trace("更新插件...", "update-plugin")
|
||||
|
||||
plugin_container = self.ap.plugin_mgr.get_plugin_by_name(plugin_name)
|
||||
|
||||
if plugin_container is None:
|
||||
@@ -133,7 +144,9 @@ class GitHubRepoInstaller(installer.PluginInstaller):
|
||||
if plugin_container.plugin_source:
|
||||
plugin_source = plugin_container.plugin_source
|
||||
|
||||
await self.install_plugin(plugin_source)
|
||||
task_context.trace("转交安装任务.", "update-plugin")
|
||||
|
||||
await self.install_plugin(plugin_source, task_context)
|
||||
|
||||
else:
|
||||
raise errors.PluginInstallerError('插件无源码信息,无法更新')
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import typing
|
||||
import traceback
|
||||
|
||||
from ..core import app
|
||||
from ..core import app, taskmgr
|
||||
from . import context, loader, events, installer, setting, models
|
||||
from .loaders import classic
|
||||
from .installers import github
|
||||
@@ -102,10 +102,11 @@ class PluginManager:
|
||||
self,
|
||||
plugin_name: str,
|
||||
plugin_source: str=None,
|
||||
task_context: taskmgr.TaskContext = taskmgr.TaskContext.placeholder(),
|
||||
):
|
||||
"""更新插件
|
||||
"""
|
||||
await self.installer.update_plugin(plugin_name, plugin_source)
|
||||
await self.installer.update_plugin(plugin_name, plugin_source, task_context)
|
||||
|
||||
plugin_container = self.get_plugin_by_name(plugin_name)
|
||||
|
||||
@@ -120,6 +121,7 @@ class PluginManager:
|
||||
new_version="HEAD"
|
||||
)
|
||||
|
||||
|
||||
def get_plugin_by_name(self, plugin_name: str) -> context.RuntimeContainer:
|
||||
"""通过插件名获取插件
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user