Fix expired ingest task stuck state

This commit is contained in:
2026-07-19 22:17:35 +08:00
parent 12b7e31783
commit 4327b94fd0
4 changed files with 26 additions and 4 deletions
@@ -81,7 +81,8 @@ public class IngestController {
public Result<IngestStatusResponse> statusById(@PathVariable("taskId") String taskId) {
ProgressMessage pm = progressStore.get(taskId);
if (pm == null) {
return Result.success(new IngestStatusResponse(taskId, running.get(), false,
boolean isRunning = running.get();
return Result.success(new IngestStatusResponse(taskId, isRunning, !isRunning,
0, 0, 0, 0, 0, 0, 0, 0, "未找到任务或已过期"));
}
@@ -8,6 +8,7 @@ import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -159,4 +160,19 @@ class ProgressMessageMappingTest {
com.music.common.Result<?> result = controller.start(new com.music.dto.IngestRequest());
assertTrue(result.getCode() == 0);
}
@Test
void ingestControllerTreatsMissingStoppedTaskAsTerminal() throws Exception {
ConfigService cfgService = mock(ConfigService.class);
ProgressStore store = new ProgressStore();
com.music.controller.IngestController controller = new com.music.controller.IngestController(
mock(IngestService.class), store, cfgService);
com.music.common.Result<com.music.dto.IngestStatusResponse> result =
controller.statusById("expired-task");
assertFalse(result.getData().isRunning());
assertTrue(result.getData().isCompleted());
assertEquals("未找到任务或已过期", result.getData().getMessage());
}
}
+6 -3
View File
@@ -532,8 +532,9 @@ function handleProgressMessage(msg: ProgressMessage) {
Object.assign(progress, msg);
recordActivity(msg);
submitting.value = !msg.completed && (submitting.value || !!msg.taskId);
if (msg.completed) {
if (typeof msg.running === 'boolean') {
submitting.value = msg.running;
} else if (msg.completed) {
submitting.value = false;
}
@@ -558,6 +559,7 @@ function statusToProgress(resp: IngestStatusResponse): ProgressMessage {
currentFile: '',
message: resp.message,
completed: resp.completed,
running: resp.running,
ingestedFiles: resp.ingestedFiles,
duplicateFiles: resp.duplicateFiles,
missingMetadataFiles: resp.missingMetadataFiles,
@@ -575,8 +577,9 @@ function startPolling() {
const resp = await getIngestStatus(taskId.value);
if (resp) {
handleProgressMessage(statusToProgress(resp));
if (resp.completed) {
if (resp.completed || !resp.running) {
stopPolling();
wsDisconnect();
}
}
} catch {
+2
View File
@@ -12,6 +12,8 @@ export interface ProgressMessage {
currentFile: string;
message: string;
completed: boolean;
/** REST 状态查询提供;WebSocket 进度消息通常不包含此字段。 */
running?: boolean;
duplicateGroups?: number;
movedFiles?: number;
organizedFiles?: number;