Fix task status stuck at 'running': use new DB session in thread, add frontend auto-polling

This commit is contained in:
Yuzhiran Dev
2026-05-18 22:37:59 +08:00
parent 33766a396d
commit f427aea1b3
2 changed files with 37 additions and 17 deletions
+12 -1
View File
@@ -187,6 +187,7 @@ const TasksApp = {
showDetailDialog: false, detailTask: null,
schedulerJobs: [], schedulerLoading: false,
totalTasks: 0, currentPage: 1, pageSize: 20,
pollTimer: null,
SCHEDULER_JOBS,
}
},
@@ -236,6 +237,13 @@ const TasksApp = {
if (!dateStr) return '-';
try { return new Date(dateStr).toLocaleString('zh-CN'); } catch (e) { return dateStr; }
},
startPolling() {
this.stopPolling();
this.pollTimer = setInterval(() => this.loadTasks(), 5000);
},
stopPolling() {
if (this.pollTimer) { clearInterval(this.pollTimer); this.pollTimer = null; }
},
async loadTasks() {
this.loading = true;
try {
@@ -244,6 +252,8 @@ const TasksApp = {
const data = await this.api(url) || [];
this.tasks = data;
this.totalTasks = data.length < this.pageSize ? (this.currentPage - 1) * this.pageSize + data.length : this.currentPage * this.pageSize + 1;
const hasRunning = data.some(t => t.status === 'running');
if (hasRunning) { this.startPolling(); } else { this.stopPolling(); }
} catch (e) { console.error(e); this.$message.error('加载任务列表失败: ' + e.message); }
finally { this.loading = false; }
},
@@ -265,7 +275,8 @@ const TasksApp = {
} catch (e) { this.$message.error('重试失败: ' + e.message); }
}
},
mounted() { this.checkAuth(); }
mounted() { this.checkAuth(); },
beforeUnmount() { this.stopPolling(); }
};
const app = Vue.createApp(TasksApp);
app.use(ElementPlus);