diff --git a/app.py b/app.py index e469151..3446c4e 100755 --- a/app.py +++ b/app.py @@ -2872,26 +2872,38 @@ def scheduled_task_worker(): for schedule_config in enabled_schedules: schedule_time = schedule_config['schedule_time'] schedule_name = schedule_config.get('name', '未命名任务') - print(f"[定时任务检查] 任务 '{schedule_name}': 设定时间={schedule_time}, 当前时间={current_time}, 匹配={schedule_time == current_time}") + schedule_id = schedule_config['id'] + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}': 设定时间={schedule_time}, 当前时间={current_time}, 匹配={schedule_time == current_time}") # 检查时间是否匹配 if schedule_config['schedule_time'] != current_time: + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 跳过: 时间不匹配") continue + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 时间匹配,继续检查...") + # 检查星期是否匹配 allowed_weekdays = [int(d) for d in schedule_config.get('weekdays', '1,2,3,4,5').split(',') if d.strip()] + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 允许星期: {allowed_weekdays}, 当前星期: {current_weekday}") if current_weekday not in allowed_weekdays: + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 跳过: 星期不匹配") continue + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 星期匹配,继续检查...") + # 检查今天是否已经执行过 last_run = schedule_config.get('last_run_at') + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 最后执行时间: {last_run}") if last_run: try: last_run_date = datetime.strptime(last_run, '%Y-%m-%d %H:%M:%S').date() if last_run_date == now.date(): + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 跳过: 今天已执行过") continue # 今天已执行过 - except: - pass + except Exception as e: + print(f"[定时任务检查] 任务#{schedule_id} '{schedule_name}' 解析last_run时间失败: {e}") + + print(f"[定时任务检查] ✅ 任务#{schedule_id} '{schedule_name}' 通过所有检查,准备执行!") # 执行用户定时任务 user_id = schedule_config['user_id']