fix(download): 连续 3 轮查不到才判移除(M1)
qB 列表与按 hash 都查不到时先记 missing_since / missing_count,连续 MISSING_CONFIRM_ROUNDS(3) 轮才判 removed;中途重新出现或只是去掉管理标签即清零。相关测试改为同步多轮后再断言移除。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
cba5de731b
commit
d96f0ff19f
4 files changed
+25
-6
No files matched your search
@@ -718,6 +718,9 @@ export interface SyncStats {
|
||||
thresholdResumed: number;
|
||||
}
|
||||
|
||||
/** 连续多少轮同步(列表 + 按 hash 查)都查不到才判 removed;与资产对账的 missingConfirmAfter 同口径 */
|
||||
export const MISSING_CONFIRM_ROUNDS = 3;
|
||||
|
||||
export async function syncDownloads(d: AoDeps): Promise<SyncStats> {
|
||||
const stats: SyncStats = {
|
||||
instances: 0,
|
||||
@@ -797,13 +800,20 @@ async function syncInstance(d: AoDeps, topo: InstanceTopology, stats: SyncStats)
|
||||
// 管理标签被移除:停止后续自动动作,保留历史与资产
|
||||
await trx
|
||||
.updateTable("download_task")
|
||||
.set({ managed: false, tags: still.tags, last_synced_at: now })
|
||||
.set({ managed: false, tags: still.tags, last_synced_at: now, missing_since: null, missing_count: 0 })
|
||||
.where("id", "=", row.id)
|
||||
.execute();
|
||||
} else if (row.missing_count + 1 < MISSING_CONFIRM_ROUNDS) {
|
||||
// 列表与按 hash 都查不到:先记缺席(qB 刚重启、任务还没加载完时会短暂返回空 / 部分列表)
|
||||
await trx
|
||||
.updateTable("download_task")
|
||||
.set({ missing_since: row.missing_since ?? now, missing_count: row.missing_count + 1, last_synced_at: now })
|
||||
.where("id", "=", row.id)
|
||||
.execute();
|
||||
} else {
|
||||
await trx
|
||||
.updateTable("download_task")
|
||||
.set({ status: "removed", removed_at: now, last_synced_at: now })
|
||||
.set({ status: "removed", removed_at: now, last_synced_at: now, missing_count: row.missing_count + 1 })
|
||||
.where("id", "=", row.id)
|
||||
.execute();
|
||||
await emitStatus(d, trx, row.id, row.status, "removed", null);
|
||||
@@ -892,6 +902,8 @@ async function observeLocked(
|
||||
last_progress_at: lastProgressAt,
|
||||
no_progress_since: noProgressSince,
|
||||
last_synced_at: now,
|
||||
missing_since: null,
|
||||
missing_count: 0,
|
||||
...(becameComplete ? { completed_at: now } : {}),
|
||||
})
|
||||
.where("id", "=", row.id)
|
||||
|
||||
Reference in new issue
Block a user