fix(snapshot): 进度写 DB 改为每 2 秒一次,避免前端长时间显示 0%
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f14f685ea9
commit
669a8a7248
|
|
@ -112,10 +112,13 @@ export class SnapshotOrchestratorService implements OnModuleInit {
|
||||||
throw new Error(`备份处理器不存在: ${target}`);
|
throw new Error(`备份处理器不存在: ${target}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastDbWriteTime = 0;
|
||||||
const result = await handler.execute(outputDir, (percent, msg) => {
|
const result = await handler.execute(outputDir, (percent, msg) => {
|
||||||
this.gateway.emitProgress(taskId, target, percent, msg);
|
this.gateway.emitProgress(taskId, target, percent, msg);
|
||||||
// 进度更新不频繁写库,每10%写一次
|
// 每 2 秒写一次 DB,保证前端轮询能看到进度变化
|
||||||
if (percent % 10 === 0) {
|
const now = Date.now();
|
||||||
|
if (now - lastDbWriteTime >= 2000) {
|
||||||
|
lastDbWriteTime = now;
|
||||||
this.repo.updateDetailProgress(taskId, target, percent).catch(() => {});
|
this.repo.updateDetailProgress(taskId, target, percent).catch(() => {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue