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
@@ -4,10 +4,10 @@ import base64
|
||||
import hashlib
|
||||
import io
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from edkb_system.contracts import Block, Context
|
||||
from edkb_system.skills.soffice_util import convert_with_soffice
|
||||
|
||||
|
||||
def _to_data_uri(blob: bytes, content_type: str) -> str:
|
||||
@@ -15,17 +15,14 @@ def _to_data_uri(blob: bytes, content_type: str) -> str:
|
||||
|
||||
|
||||
def _convert_ppt_to_pptx(path: Path, out_dir: Path) -> Path:
|
||||
"""将 .ppt 转为 .pptx;soffice 超时由 soffice_util 控制。"""
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [
|
||||
proc = convert_with_soffice(
|
||||
"soffice",
|
||||
"--headless",
|
||||
"--convert-to",
|
||||
"pptx",
|
||||
str(path),
|
||||
"--outdir",
|
||||
str(out_dir),
|
||||
]
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
convert_to="pptx",
|
||||
source_path=path,
|
||||
out_dir=out_dir,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError("Install LibreOffice to convert .ppt to .pptx")
|
||||
output = out_dir / f"{path.stem}.pptx"
|
||||
@@ -35,20 +32,19 @@ def _convert_ppt_to_pptx(path: Path, out_dir: Path) -> Path:
|
||||
|
||||
|
||||
def _convert_presentation_to_pdf(path: Path, out_dir: Path) -> Path | None:
|
||||
"""将演示文稿转为 PDF;失败或超时返回 None,由上层选择其它解析路径。"""
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [
|
||||
"soffice",
|
||||
"--headless",
|
||||
"--convert-to",
|
||||
"pdf",
|
||||
str(path),
|
||||
"--outdir",
|
||||
str(out_dir),
|
||||
]
|
||||
try:
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
proc = convert_with_soffice(
|
||||
"soffice",
|
||||
convert_to="pdf",
|
||||
source_path=path,
|
||||
out_dir=out_dir,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
except RuntimeError:
|
||||
return None
|
||||
if proc.returncode != 0:
|
||||
return None
|
||||
output = out_dir / f"{path.stem}.pdf"
|
||||
|
||||
Reference in new issue
Block a user