添加详细的定时任务调试日志
为了帮助诊断用户定时任务无法执行的问题,在每个检查点添加详细日志: 1. 任务ID和名称 2. 时间匹配检查结果 3. 星期匹配检查结果 4. 今日执行状态检查结果 5. 最终是否通过所有检查 现在可以通过应用日志清晰看到每个任务在哪个检查点被跳过。 位置: app.py 第2872-2906行 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
18
app.py
18
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']
|
||||
|
||||
Reference in New Issue
Block a user