Template
Fix expired ingest task stuck state
This commit is contained in:
@@ -81,7 +81,8 @@ public class IngestController {
|
|||||||
public Result<IngestStatusResponse> statusById(@PathVariable("taskId") String taskId) {
|
public Result<IngestStatusResponse> statusById(@PathVariable("taskId") String taskId) {
|
||||||
ProgressMessage pm = progressStore.get(taskId);
|
ProgressMessage pm = progressStore.get(taskId);
|
||||||
if (pm == null) {
|
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, "未找到任务或已过期"));
|
0, 0, 0, 0, 0, 0, 0, 0, "未找到任务或已过期"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -159,4 +160,19 @@ class ProgressMessageMappingTest {
|
|||||||
com.music.common.Result<?> result = controller.start(new com.music.dto.IngestRequest());
|
com.music.common.Result<?> result = controller.start(new com.music.dto.IngestRequest());
|
||||||
assertTrue(result.getCode() == 0);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,8 +532,9 @@ function handleProgressMessage(msg: ProgressMessage) {
|
|||||||
Object.assign(progress, msg);
|
Object.assign(progress, msg);
|
||||||
recordActivity(msg);
|
recordActivity(msg);
|
||||||
|
|
||||||
submitting.value = !msg.completed && (submitting.value || !!msg.taskId);
|
if (typeof msg.running === 'boolean') {
|
||||||
if (msg.completed) {
|
submitting.value = msg.running;
|
||||||
|
} else if (msg.completed) {
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,6 +559,7 @@ function statusToProgress(resp: IngestStatusResponse): ProgressMessage {
|
|||||||
currentFile: '',
|
currentFile: '',
|
||||||
message: resp.message,
|
message: resp.message,
|
||||||
completed: resp.completed,
|
completed: resp.completed,
|
||||||
|
running: resp.running,
|
||||||
ingestedFiles: resp.ingestedFiles,
|
ingestedFiles: resp.ingestedFiles,
|
||||||
duplicateFiles: resp.duplicateFiles,
|
duplicateFiles: resp.duplicateFiles,
|
||||||
missingMetadataFiles: resp.missingMetadataFiles,
|
missingMetadataFiles: resp.missingMetadataFiles,
|
||||||
@@ -575,8 +577,9 @@ function startPolling() {
|
|||||||
const resp = await getIngestStatus(taskId.value);
|
const resp = await getIngestStatus(taskId.value);
|
||||||
if (resp) {
|
if (resp) {
|
||||||
handleProgressMessage(statusToProgress(resp));
|
handleProgressMessage(statusToProgress(resp));
|
||||||
if (resp.completed) {
|
if (resp.completed || !resp.running) {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
|
wsDisconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export interface ProgressMessage {
|
|||||||
currentFile: string;
|
currentFile: string;
|
||||||
message: string;
|
message: string;
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
|
/** REST 状态查询提供;WebSocket 进度消息通常不包含此字段。 */
|
||||||
|
running?: boolean;
|
||||||
duplicateGroups?: number;
|
duplicateGroups?: number;
|
||||||
movedFiles?: number;
|
movedFiles?: number;
|
||||||
organizedFiles?: number;
|
organizedFiles?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user