diff --git a/packages/contracts/src/execution.ts b/packages/contracts/src/execution.ts index 3760a9e3..f3d67091 100644 --- a/packages/contracts/src/execution.ts +++ b/packages/contracts/src/execution.ts @@ -223,6 +223,11 @@ export const DownloadTask = EntityBase.extend({ removedAt: Timestamp.nullable(), fileList: z.array(z.object({ path: z.string(), size: NonNegInt, progress: z.number().optional() })).nullable(), lastError: JsonObject.nullable(), + /** 下载器里连续查不到的起点与轮数:达到阈值才判 removed,中途出现即清零 */ + missingSince: Timestamp.nullable().optional(), + missingCount: NonNegInt.optional(), + /** removed 行被再次提交 / 接管复活的次数(完成事件幂等键随之换代) */ + generation: NonNegInt.optional(), }); export type DownloadTask = z.infer; export const DownloadTaskCreate = DownloadTask.pick({ diff --git a/packages/db/migrations/0067_download_missing.ts b/packages/db/migrations/0067_download_missing.ts new file mode 100644 index 00000000..cb07d1ea --- /dev/null +++ b/packages/db/migrations/0067_download_missing.ts @@ -0,0 +1,25 @@ +import type { Kysely } from "kysely"; +import { execDdl } from "../src/migration-helpers.ts"; + +// 下载调度卡死修复(docs/plan/system-review.md ③): +// - missing_since / missing_count:qB 列表与按 hash 查都查不到时先记缺席,连续多轮才判 removed,中途出现即清零 +// - generation:同一 (实例, hash) 的 removed 行被再次提交 / 接管而复活时 +1,完成事件幂等键随之换代, +// 复活后的完成仍能触发整理 +// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 +export async function up(db: Kysely): Promise { + await execDdl( + db, + `alter table download_task add column if not exists missing_since timestamptz; + alter table download_task add column if not exists missing_count integer not null default 0; + alter table download_task add column if not exists generation integer not null default 0;`, + ); +} +// biome-ignore lint/suspicious/noExplicitAny: 同上 +export async function down(db: Kysely): Promise { + await execDdl( + db, + `alter table download_task drop column if exists missing_since; + alter table download_task drop column if exists missing_count; + alter table download_task drop column if exists generation;`, + ); +} diff --git a/packages/db/src/types.ts b/packages/db/src/types.ts index 3f2a61ad..fd43bdb1 100644 --- a/packages/db/src/types.ts +++ b/packages/db/src/types.ts @@ -719,6 +719,9 @@ export interface DownloadTaskTable { updated_at: GeneratedTimestamptz; media_entity_id: string | null; import_plan_id: string | null; + missing_since: Timestamptz | null; + missing_count: Generated; + generation: Generated; } export interface DownloaderInstanceTable {