fix(transfer): keep task active after table errors

This commit is contained in:
Guoyu Su authored and GitHub committed 2026-07-09 18:30:29 +08:00
1 parent e25be6335d
commit 15d392bc44
9 files changed
+119 -11

No files matched your search

@@ -1,5 +1,6 @@
import { reactive, computed } from "vue";
import * as api from "@/lib/backend/api";
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
export type BackgroundTaskKind = "table-export" | "database-export" | "sql-file" | "data-transfer";
export type BackgroundTaskStatus = "Running" | "Writing" | "Done" | "Error" | "Cancelled";
@@ -46,9 +47,9 @@ function normalizeSqlFileStatus(status: api.SqlFileStatus): BackgroundTaskStatus
return "Running";
}
function normalizeTransferStatus(status: api.TransferProgress["status"]): BackgroundTaskStatus {
function normalizeTransferStatus(status: api.TransferProgress["status"], terminal: boolean): BackgroundTaskStatus {
if (status === "done") return "Done";
if (status === "error") return "Error";
if (status === "error") return terminal ? "Error" : "Running";
if (status === "cancelled") return "Cancelled";
return "Running";
}
@@ -200,7 +201,7 @@ export function useExportTracker() {
void (async () => {
try {
await api.startTransfer(request, (progress) => {
terminalStatus = progress.status === "done" || progress.status === "error" || progress.status === "cancelled" ? progress.status : terminalStatus;
terminalStatus = isTerminalTransferProgress(progress) ? progress.status : terminalStatus;
updateDataTransferTask(progress.transferId, progress);
});
@@ -217,6 +218,7 @@ export function useExportTracker() {
totalRows: task.totalRows,
status: "error",
error: e?.message || String(e),
terminal: true,
});
} finally {
activeTransferRuns.delete(request.transferId);
@@ -266,7 +268,7 @@ export function useExportTracker() {
function updateDataTransferTask(transferId: string, progress: api.TransferProgress) {
const task = taskMap.get(transferId);
if (!task) return;
const nextStatus = normalizeTransferStatus(progress.status);
const nextStatus = normalizeTransferStatus(progress.status, progress.terminal);
const hadError = task.status === "Error";
task.status = hadError && nextStatus === "Done" ? "Error" : nextStatus;
task.errorMessage = progress.error || task.errorMessage || null;
+2 -1
View File
@@ -100,6 +100,7 @@ import type {
AppSupportInfo,
} from "@/lib/backend/tauri";
import type { QueryEditability } from "@/lib/sql/sqlAnalysis";
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
import type {
DataGridColumnDistinctValuesSqlOptions,
DataGridColumnValueFilterConditionOptions,
@@ -1316,7 +1317,7 @@ export async function startTransfer(request: TransferRequest, onProgress: (progr
es.onmessage = (e) => {
const progress: TransferProgress = JSON.parse(e.data);
onProgress(progress);
if (progress.status === "done" || progress.status === "error" || progress.status === "cancelled") {
if (isTerminalTransferProgress(progress)) {
es.close();
resolve();
}
+3 -1
View File
@@ -38,6 +38,7 @@ import type { CollectionInfo } from "@/types/database";
import type { SidebarObjectKind } from "@/lib/database/databaseObjectCapabilities";
import type { AiConfig, AiTestConnectionResult } from "@/stores/settingsStore";
import type { QueryEditability } from "@/lib/sql/sqlAnalysis";
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
import type {
DataGridColumnDistinctValuesSqlOptions,
DataGridColumnValueFilterConditionOptions,
@@ -1942,6 +1943,7 @@ export interface TransferProgress {
totalRows: number | null;
status: "running" | "tableDone" | "done" | "error" | "cancelled";
error: string | null;
terminal: boolean;
}
export async function startTransfer(request: TransferRequest, onProgress: (progress: TransferProgress) => void): Promise<void> {
@@ -1952,7 +1954,7 @@ export async function startTransfer(request: TransferRequest, onProgress: (progr
unlisten = await listen<TransferProgress>("transfer-progress", (event) => {
if (event.payload.transferId !== request.transferId) return;
onProgress(event.payload);
if (event.payload.status === "done" || event.payload.status === "error" || event.payload.status === "cancelled") {
if (isTerminalTransferProgress(event.payload)) {
unlisten?.();
resolve();
}
@@ -0,0 +1,8 @@
type TransferProgressTerminalState = {
terminal?: boolean;
status: "running" | "tableDone" | "done" | "error" | "cancelled";
};
export function isTerminalTransferProgress(progress: TransferProgressTerminalState): boolean {
return progress.terminal === true || progress.status === "done" || progress.status === "cancelled";
}