From 1ea7b7527f006ca5d69d1195924d4aae46dd8353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Fri, 4 Sep 2026 11:21:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=B4=E9=9C=B2=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=A7=A3=E6=9E=90=E4=BB=BB=E5=8A=A1=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/async/DocumentAsyncTaskManager.java | 3 +- .../DocumentAsyncTaskNotFoundException.java | 29 +++++++++++++++++++ .../async/DocumentAsyncTaskManagerTest.java | 16 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/exception/DocumentAsyncTaskNotFoundException.java diff --git a/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/async/DocumentAsyncTaskManager.java b/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/async/DocumentAsyncTaskManager.java index 5536b02..156cb86 100644 --- a/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/async/DocumentAsyncTaskManager.java +++ b/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/async/DocumentAsyncTaskManager.java @@ -2,6 +2,7 @@ package com.easyagents.document.core.async; import com.easyagents.core.util.StringUtil; import com.easyagents.document.core.exception.DocumentParseException; +import com.easyagents.document.core.exception.DocumentAsyncTaskNotFoundException; import com.easyagents.document.core.entity.ParseResponse; import com.easyagents.document.core.entity.ParseTaskInfo; import com.easyagents.document.core.entity.ParseTaskStatus; @@ -135,7 +136,7 @@ public class DocumentAsyncTaskManager { } DocumentAsyncTaskRecord record = repository.find(taskId); if (record == null) { - throw new DocumentParseException("Document async task not found: " + taskId); + throw new DocumentAsyncTaskNotFoundException(taskId); } return record; } diff --git a/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/exception/DocumentAsyncTaskNotFoundException.java b/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/exception/DocumentAsyncTaskNotFoundException.java new file mode 100644 index 0000000..cbe9d07 --- /dev/null +++ b/easy-agents-document/easy-agents-document-core/src/main/java/com/easyagents/document/core/exception/DocumentAsyncTaskNotFoundException.java @@ -0,0 +1,29 @@ +package com.easyagents.document.core.exception; + +/** + * 进程内异步文档任务不存在。 + * + *
本地 Office 解析任务允许使用内存仓库;进程重启后,调用方可以 + * 通过该异常识别执行实例已经丢失,并从持久化业务任务重新提交。
+ * + * @author Codex + * @since 2026-09-02 + */ +public class DocumentAsyncTaskNotFoundException extends DocumentParseException { + + private final String taskId; + + public DocumentAsyncTaskNotFoundException(String taskId) { + super("Document async task not found: " + taskId); + this.taskId = taskId; + } + + /** + * 获取已丢失的任务 ID。 + * + * @return 任务 ID + */ + public String getTaskId() { + return taskId; + } +} diff --git a/easy-agents-document/easy-agents-document-core/src/test/java/com/easyagents/document/core/async/DocumentAsyncTaskManagerTest.java b/easy-agents-document/easy-agents-document-core/src/test/java/com/easyagents/document/core/async/DocumentAsyncTaskManagerTest.java index cc10ede..3a72a28 100644 --- a/easy-agents-document/easy-agents-document-core/src/test/java/com/easyagents/document/core/async/DocumentAsyncTaskManagerTest.java +++ b/easy-agents-document/easy-agents-document-core/src/test/java/com/easyagents/document/core/async/DocumentAsyncTaskManagerTest.java @@ -4,6 +4,7 @@ import com.easyagents.document.core.entity.ParseResponse; import com.easyagents.document.core.entity.ParseResult; import com.easyagents.document.core.entity.ParseTaskInfo; import com.easyagents.document.core.entity.ParseTaskStatus; +import com.easyagents.document.core.exception.DocumentAsyncTaskNotFoundException; import org.junit.Assert; import org.junit.Test; @@ -18,6 +19,21 @@ import java.util.concurrent.Executor; */ public class DocumentAsyncTaskManagerTest { + @Test + public void shouldExposeMissingInMemoryTaskAsRecoverableSignal() { + DocumentAsyncTaskManager manager = new DocumentAsyncTaskManager( + new InMemoryDocumentAsyncTaskRepository(), + Runnable::run + ); + + try { + manager.queryTaskInfo("lost-task"); + Assert.fail("expected DocumentAsyncTaskNotFoundException"); + } catch (DocumentAsyncTaskNotFoundException error) { + Assert.assertEquals("lost-task", error.getTaskId()); + } + } + @Test public void shouldTrackTaskLifecycleAndResult() { Executor directExecutor = new Executor() {