mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
fix: 保持SSE长连接不断开,移除主动closeConnection逻辑
前端修复: - init()无条件建立SSE连接 - error handler无条件重连,去掉hasActiveTasks判断 后端修复: - notifyAllTasksCompleted不再延迟关闭连接 - SSE保持长连接持续接收任务状态更新
This commit is contained in:
@@ -203,13 +203,10 @@ export const useImportTaskStore = defineStore('import-task', () => {
|
||||
connection.addEventListener('error', (event) => {
|
||||
console.error('SSE连接错误:', event);
|
||||
sseConnected.value = false;
|
||||
// 如果连接关闭,尝试重连
|
||||
// 如果连接关闭,无条件重连,不判断活跃任务
|
||||
if (connection.getReadyState() === EventSource.CLOSED) {
|
||||
// 延迟重连,避免频繁重连
|
||||
setTimeout(() => {
|
||||
if (hasActiveTasks.value) {
|
||||
connectSse();
|
||||
}
|
||||
connectSse();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
@@ -238,10 +235,8 @@ export const useImportTaskStore = defineStore('import-task', () => {
|
||||
async function init() {
|
||||
await fetchTasks(true);
|
||||
|
||||
// 如果有进行中的任务,建立SSE连接
|
||||
if (hasActiveTasks.value && !sseConnection.value) {
|
||||
connectSse();
|
||||
}
|
||||
// 页面加载时无条件建立SSE连接,接收实时任务状态更新
|
||||
connectSse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-15
@@ -960,21 +960,6 @@ const handleCreateTask = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
|
||||
// 确保SSE连接已建立(如果还没有连接,先建立连接)
|
||||
if (!importTaskStore.sseConnection || !importTaskStore.sseConnected) {
|
||||
message.loading('正在建立连接...', 0);
|
||||
try {
|
||||
await importTaskStore.connectSse();
|
||||
message.destroy();
|
||||
} catch (error: any) {
|
||||
message.destroy();
|
||||
message.error(
|
||||
error?.message || '建立SSE连接失败,无法实时接收任务进度',
|
||||
);
|
||||
// 即使连接失败,也允许继续创建任务
|
||||
}
|
||||
}
|
||||
|
||||
// 先上传文件到 OSS(使用统一文件系统)
|
||||
message.loading('正在上传文件...', 0);
|
||||
const fileInfo = await uploadFileToOss(selectedFile.value, {
|
||||
|
||||
Reference in New Issue
Block a user