From d77595eba02949cfc55da61ea29e5967399291ba Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Sat, 13 Dec 2025 03:38:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=A5=E5=BF=97=E9=87=8D=E5=A4=8D=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加配置变化检测,只在首次运行或配置变化时打印日志 - 避免每5秒重复打印相同的定时任务设置日志 - 减少日志噪音,提高日志可读性 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 46150b3..9651046 100755 --- a/app.py +++ b/app.py @@ -3978,10 +3978,19 @@ def scheduled_task_worker(): import traceback traceback.print_exc() + # 用于跟踪配置变化,避免重复打印日志 + last_config_hash = [None] # 使用列表以便在闭包中修改 + # 每分钟检查一次配置 def check_and_schedule(): config = database.get_system_config() + # 计算配置哈希,检测配置是否变化 + config_hash = (config.get('schedule_enabled'), config.get('schedule_time', '02:00')) + config_changed = (last_config_hash[0] != config_hash) + is_first_run = (last_config_hash[0] is None) + last_config_hash[0] = config_hash + # 清除旧的任务 schedule.clear() @@ -4004,18 +4013,25 @@ def scheduled_task_worker(): # 始终添加每天凌晨3点(CST)的数据清理任务 cleanup_utc_time = cst_to_utc_time("03:00") schedule.every().day.at(cleanup_utc_time).do(cleanup_old_data) - print(f"[定时任务] 已设置数据清理任务: 每天 CST 03:00 (UTC {cleanup_utc_time})") # 每小时清理过期验证码 schedule.every().hour.do(cleanup_expired_captcha) - print(f"[定时任务] 已设置验证码清理任务: 每小时执行一次") + + # 只在首次运行时打印基础任务日志 + if is_first_run: + print(f"[定时任务] 已设置数据清理任务: 每天 CST 03:00 (UTC {cleanup_utc_time})") + print(f"[定时任务] 已设置验证码清理任务: 每小时执行一次") # 如果启用了定时浏览任务,则添加 if config.get('schedule_enabled'): schedule_time_cst = config.get('schedule_time', '02:00') schedule_time_utc = cst_to_utc_time(schedule_time_cst) schedule.every().day.at(schedule_time_utc).do(run_scheduled_task) - print(f"[定时任务] 已设置浏览任务: 每天 CST {schedule_time_cst} (UTC {schedule_time_utc})") + # 只在首次运行或配置变化时打印 + if is_first_run or config_changed: + print(f"[定时任务] 已设置浏览任务: 每天 CST {schedule_time_cst} (UTC {schedule_time_utc})") + elif config_changed and not is_first_run: + print(f"[定时任务] 浏览任务已禁用") # 初始检查 check_and_schedule()