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
@@ -14,6 +14,7 @@ import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
|
||||
from edkb_system.contracts import Block, Context
|
||||
from edkb_system.skills.soffice_util import convert_with_soffice, soffice_candidates
|
||||
from edkb_system.skills.word_bridge import convert_with_word
|
||||
|
||||
|
||||
@@ -1583,6 +1584,11 @@ def _convert_doc_with_word(path: Path, out_dir: Path) -> Path:
|
||||
|
||||
|
||||
def _convert_doc_to_docx(path: Path, out_dir: Path) -> Path:
|
||||
"""
|
||||
将 .doc 转为 .docx。
|
||||
|
||||
Windows 优先 Word COM;Linux/容器走 soffice_util(带 EDKB_SOFFICE_TIMEOUT_SEC 超时)。
|
||||
"""
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
output = out_dir / f"{path.stem}.docx"
|
||||
force_reconvert = str(
|
||||
@@ -1606,29 +1612,24 @@ def _convert_doc_to_docx(path: Path, out_dir: Path) -> Path:
|
||||
except Exception as exc:
|
||||
errors.append(f"Word COM conversion failed: {exc}")
|
||||
|
||||
soffice_candidates = [
|
||||
os.environ.get("EDKB_SOFFICE"),
|
||||
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
||||
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
||||
"soffice",
|
||||
]
|
||||
for soffice in soffice_candidates:
|
||||
# 非 Windows:依次尝试 soffice 候选路径,单次转换受 soffice_util 超时保护
|
||||
soffice_candidates_list = soffice_candidates()
|
||||
for soffice in soffice_candidates_list:
|
||||
if not soffice:
|
||||
continue
|
||||
cmd = [
|
||||
soffice,
|
||||
"--headless",
|
||||
"--convert-to",
|
||||
"docx",
|
||||
str(path),
|
||||
"--outdir",
|
||||
str(out_dir),
|
||||
]
|
||||
try:
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
proc = convert_with_soffice(
|
||||
soffice,
|
||||
convert_to="docx",
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user