fix: 给 soffice 加超时(120s)机制、worker 自动回收超时 running 任务,避免任务挂死阻塞队列

This commit is contained in:
sophie committed 2026-05-29 11:37:02 +08:00
1 parent 1d72018eb7
commit 0eb577df1a
11 files changed
+379 -88

No files matched your search

@@ -325,6 +325,12 @@ def run_path_upload_job(job_id: int) -> tuple[bool, str]:
return True, 'ok'
def _is_clean_timeout_error(exc: Exception) -> bool:
"""判断清洗异常是否由 soffice / 子进程超时引起(与 soffice_util 错误文案对齐)。"""
message = str(exc).lower()
return 'timed out' in message or 'timeout' in message
def run_clean_job(job_id: int) -> tuple[bool, str]:
"""
第一版最小清洗任务执行器。
@@ -378,6 +384,18 @@ def run_clean_job(job_id: int) -> tuple[bool, str]:
result = build_clean_result(source_path, target_dir)
job_message = '真实清洗结果已生成'
except Exception as exc:
# soffice 超时等不可恢复错误:直接失败,避免回退占位结果掩盖问题
if _is_clean_timeout_error(exc):
job.status = 'failed'
job.progress = 100
job.message = '清洗超时'
job.error_message = str(exc)
job.finished_at = _utc_now()
version.status = 'failed'
version.error_message = str(exc)
db.session.commit()
return False, 'timeout'
preview_path = target_dir / f'{_normalized_source_filename(version, source_path)}.preview.txt'
preview_path.write_text(
'\n'.join([