From 48d85b798b6d09614ff21622e2718382fd0a4d5d Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 17 Aug 2026 13:29:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(scheduler):=20=E4=B8=8B=E8=BD=BD=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=86=B7=E5=8D=B4=E8=AE=B0=E5=BD=95=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 DATA_CLEANUP_DOWNLOAD_FAILURE_DAYS 配置项(默认 7 天), 在 _build_cleanup_plans 中增加 downloadfailure 清理计划, 调用已有的 DownloadFailure.delete_expired 删除冷却已过期的记录。 --- app/runtime/config.py | 2 ++ app/scheduler.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/runtime/config.py b/app/runtime/config.py index 9305ca3a4..6287dde96 100644 --- a/app/runtime/config.py +++ b/app/runtime/config.py @@ -194,6 +194,8 @@ class ConfigModel(BaseModel): DATA_CLEANUP_SITE_USERDATA_DAYS: int = 180 # 整理历史表保留天数,0为不清理 DATA_CLEANUP_TRANSFER_HISTORY_DAYS: int = 365 * 3 + # 下载失败冷却记录保留天数,0为不清理 + DATA_CLEANUP_DOWNLOAD_FAILURE_DAYS: int = 7 # ==================== 缓存配置 ==================== # 缓存类型,支持 cachetools 和 redis,默认使用 cachetools diff --git a/app/scheduler.py b/app/scheduler.py index 21123c7d8..342b1950c 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -31,6 +31,7 @@ from app.runtime.extensions.plugin_manager import PluginManager from app.db import SessionFactory from app.db.oper.agenttask import AgentTaskOper from app.db.models.downloadhistory import DownloadHistory, DownloadFiles +from app.db.models.downloadfailure import DownloadFailure from app.db.models.message import Message as MessageModel from app.db.models.siteuserdata import SiteUserData from app.db.models.transferhistory import TransferHistory @@ -180,6 +181,9 @@ class SchedulerChain(ChainBase): transfer_history_days = self._normalize_retention_days( settings.DATA_CLEANUP_TRANSFER_HISTORY_DAYS ) + download_failure_days = self._normalize_retention_days( + settings.DATA_CLEANUP_DOWNLOAD_FAILURE_DAYS + ) message_cutoff = ( started_at - timedelta(days=message_days) @@ -193,6 +197,9 @@ class SchedulerChain(ChainBase): transfer_history_cutoff = ( started_at - timedelta(days=transfer_history_days) ).strftime("%Y-%m-%d") + download_failure_cutoff = ( + started_at - timedelta(days=download_failure_days) + ).strftime("%Y-%m-%d %H:%M:%S") return [ { @@ -244,6 +251,16 @@ class SchedulerChain(ChainBase): limit=batch_size, ), }, + { + "name": "downloadfailure", + "retention_days": download_failure_days, + "cutoff": download_failure_cutoff, + "handler": lambda db: DownloadFailure.delete_expired( + db=db, + before_time=download_failure_cutoff, + limit=batch_size, + ), + }, ] @staticmethod