feat(scheduler): 下载失败冷却记录加入定时清理

新增 DATA_CLEANUP_DOWNLOAD_FAILURE_DAYS 配置项(默认 7 天),
在 _build_cleanup_plans 中增加 downloadfailure 清理计划,
调用已有的 DownloadFailure.delete_expired 删除冷却已过期的记录。
This commit is contained in:
jxxghp
2026-08-17 13:29:42 +08:00
parent 2bb090d2be
commit 48d85b798b
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -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