fix: 给 soffice 加超时(120s)机制、worker 自动回收超时 running 任务,避免任务挂死阻塞队列
This commit is contained in:
1 parent
1d72018eb7
commit
0eb577df1a
11 files changed
+379
-88
No files matched your search
@@ -1,44 +1,41 @@
|
||||
"""
|
||||
backend/edkb_system/skills/loader_excel.py
|
||||
文件用途:加载 Excel 表格为结构化数据
|
||||
|
||||
说明:
|
||||
- .xls 旧格式先经 soffice_util 转为 .xlsx,再走 openpyxl 解析。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from edkb_system.contracts import Context
|
||||
|
||||
|
||||
def _soffice_candidates() -> list[str]:
|
||||
return [
|
||||
os.environ.get("EDKB_SOFFICE", "").strip(),
|
||||
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
||||
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
||||
"soffice",
|
||||
]
|
||||
from edkb_system.skills.soffice_util import convert_with_soffice, soffice_candidates
|
||||
|
||||
|
||||
def _convert_xls_to_xlsx(path: Path, out_dir: Path) -> Path:
|
||||
"""将 .xls 转为 .xlsx;soffice 调用带超时,见 EDKB_SOFFICE_TIMEOUT_SEC。"""
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
output = out_dir / f"{path.stem}.xlsx"
|
||||
errors: list[str] = []
|
||||
for soffice in _soffice_candidates():
|
||||
for soffice in soffice_candidates():
|
||||
if not soffice:
|
||||
continue
|
||||
cmd = [
|
||||
soffice,
|
||||
"--headless",
|
||||
"--convert-to",
|
||||
"xlsx",
|
||||
str(path),
|
||||
"--outdir",
|
||||
str(out_dir),
|
||||
]
|
||||
try:
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
proc = convert_with_soffice(
|
||||
soffice,
|
||||
convert_to="xlsx",
|
||||
source_path=path,
|
||||
out_dir=out_dir,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
errors.append(f"soffice not found: {soffice}")
|
||||
continue
|
||||
except RuntimeError as exc:
|
||||
errors.append(str(exc))
|
||||
continue
|
||||
if proc.returncode == 0 and output.exists():
|
||||
return output
|
||||
stderr = (proc.stderr or "").strip()
|
||||
|
||||
Reference in new issue
Block a user