fix: 暴露本地文档解析任务丢失状态

This commit is contained in:
2026-09-04 11:21:46 +08:00
parent 68fd303656
commit 1ea7b7527f
3 changed files with 47 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,29 @@
package com.easyagents.document.core.exception;
/**
* 进程内异步文档任务不存在。
*
* <p>本地 Office 解析任务允许使用内存仓库;进程重启后,调用方可以
* 通过该异常识别执行实例已经丢失,并从持久化业务任务重新提交。</p>
*
* @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;
}
}

View File

@@ -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() {