mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
fix: skill install timeout
This commit is contained in:
@@ -111,7 +111,7 @@ def _clone_repo(git_url: str):
|
|||||||
import subprocess
|
import subprocess
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["git", "clone", "--depth", "1", git_url, repo_dir],
|
["git", "clone", "--depth", "1", git_url, repo_dir],
|
||||||
check=True, capture_output=True, timeout=120,
|
check=True, capture_output=True, timeout=30,
|
||||||
)
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
@@ -122,7 +122,7 @@ def _clone_repo(git_url: str):
|
|||||||
return tmp_dir, repo_dir
|
return tmp_dir, repo_dir
|
||||||
|
|
||||||
|
|
||||||
def _download_repo_zip(spec: str, branch: str = "main", host: str = "github", timeout: int = 120):
|
def _download_repo_zip(spec: str, branch: str = "main", host: str = "github", timeout: int = 30):
|
||||||
"""Download a GitHub/GitLab repo as zip and extract it.
|
"""Download a GitHub/GitLab repo as zip and extract it.
|
||||||
|
|
||||||
Returns (tmp_dir, repo_root) where tmp_dir is the temp directory to clean up
|
Returns (tmp_dir, repo_root) where tmp_dir is the temp directory to clean up
|
||||||
@@ -436,7 +436,7 @@ def _install_archive_url(url: str, result: InstallResult):
|
|||||||
|
|
||||||
result.messages.append(f"Downloading archive from {url} ...")
|
result.messages.append(f"Downloading archive from {url} ...")
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url, timeout=120, allow_redirects=True)
|
resp = requests.get(url, timeout=30, allow_redirects=True)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise SkillInstallError(f"Failed to download archive: {e}")
|
raise SkillInstallError(f"Failed to download archive: {e}")
|
||||||
@@ -947,7 +947,7 @@ def _install_hub(name, result: InstallResult, provider=None):
|
|||||||
has_mirror = data.get("has_mirror", False)
|
has_mirror = data.get("has_mirror", False)
|
||||||
gh_err = None
|
gh_err = None
|
||||||
|
|
||||||
gh_timeout = 15 if has_mirror else 120
|
gh_timeout = 15 if has_mirror else 30
|
||||||
try:
|
try:
|
||||||
parsed_url = _parse_github_url(source_url)
|
parsed_url = _parse_github_url(source_url)
|
||||||
if parsed_url:
|
if parsed_url:
|
||||||
@@ -968,7 +968,7 @@ def _install_hub(name, result: InstallResult, provider=None):
|
|||||||
mirror_resp = requests.post(
|
mirror_resp = requests.post(
|
||||||
f"{SKILL_HUB_API}/skills/{name}/download",
|
f"{SKILL_HUB_API}/skills/{name}/download",
|
||||||
json={"mirror": True},
|
json={"mirror": True},
|
||||||
timeout=60,
|
timeout=30,
|
||||||
)
|
)
|
||||||
mirror_resp.raise_for_status()
|
mirror_resp.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1004,7 +1004,7 @@ def _install_hub(name, result: InstallResult, provider=None):
|
|||||||
result.messages.append(f"Source: {src_provider}")
|
result.messages.append(f"Source: {src_provider}")
|
||||||
result.messages.append("Downloading skill package...")
|
result.messages.append("Downloading skill package...")
|
||||||
dl_err = None
|
dl_err = None
|
||||||
dl_timeout = 15 if has_mirror else 60
|
dl_timeout = 15 if has_mirror else 30
|
||||||
try:
|
try:
|
||||||
dl_resp = requests.get(
|
dl_resp = requests.get(
|
||||||
download_url,
|
download_url,
|
||||||
@@ -1033,7 +1033,7 @@ def _install_hub(name, result: InstallResult, provider=None):
|
|||||||
mirror_resp = requests.post(
|
mirror_resp = requests.post(
|
||||||
f"{SKILL_HUB_API}/skills/{name}/download",
|
f"{SKILL_HUB_API}/skills/{name}/download",
|
||||||
json={"mirror": True},
|
json={"mirror": True},
|
||||||
timeout=60,
|
timeout=30,
|
||||||
)
|
)
|
||||||
mirror_resp.raise_for_status()
|
mirror_resp.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1083,7 +1083,7 @@ def _install_hub(name, result: InstallResult, provider=None):
|
|||||||
raise SkillInstallError("Unexpected response from Skill Hub.")
|
raise SkillInstallError("Unexpected response from Skill Hub.")
|
||||||
|
|
||||||
|
|
||||||
def _install_github(spec, result: InstallResult, subpath=None, skill_name=None, branch="main", source="github", timeout=120):
|
def _install_github(spec, result: InstallResult, subpath=None, skill_name=None, branch="main", source="github", timeout=30):
|
||||||
"""Install skill(s) from a GitHub repo.
|
"""Install skill(s) from a GitHub repo.
|
||||||
|
|
||||||
Strategy: zip download first (no API rate limit), Contents API as fallback.
|
Strategy: zip download first (no API rate limit), Contents API as fallback.
|
||||||
|
|||||||
@@ -655,13 +655,19 @@ class CowCliPlugin(Plugin):
|
|||||||
lines.append("💡 /skill install <名称> 安装技能")
|
lines.append("💡 /skill install <名称> 安装技能")
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
_INSTALL_TIMEOUT = 60
|
||||||
|
|
||||||
def _skill_install(self, name: str, e_context: EventContext) -> str:
|
def _skill_install(self, name: str, e_context: EventContext) -> str:
|
||||||
if not name:
|
if not name:
|
||||||
return "请指定要安装的技能: /skill install <名称>"
|
return "请指定要安装的技能: /skill install <名称>"
|
||||||
|
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FuturesTimeout
|
||||||
|
from cli.commands.skill import install_skill
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cli.commands.skill import install_skill
|
with ThreadPoolExecutor(max_workers=1) as pool:
|
||||||
result = install_skill(name)
|
future = pool.submit(install_skill, name)
|
||||||
|
result = future.result(timeout=self._INSTALL_TIMEOUT)
|
||||||
|
|
||||||
if result.error:
|
if result.error:
|
||||||
return f"安装失败: {result.error}"
|
return f"安装失败: {result.error}"
|
||||||
@@ -670,6 +676,8 @@ class CowCliPlugin(Plugin):
|
|||||||
return "\n".join(result.messages) if result.messages else "未找到可安装的技能"
|
return "\n".join(result.messages) if result.messages else "未找到可安装的技能"
|
||||||
|
|
||||||
return self._format_install_result(result)
|
return self._format_install_result(result)
|
||||||
|
except FuturesTimeout:
|
||||||
|
return "安装超时,请稍后重试或检查网络连接"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"安装失败: {e}"
|
return f"安装失败: {e}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user