添加定时任务日志管理功能

- 添加用户清空日志按钮
- 添加30天自动清理定时任务执行日志
- 简化日志API代码,移除调试日志

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-10 20:20:44 +08:00
parent 9df2122fb5
commit 7954aeaf59
3 changed files with 71 additions and 43 deletions

View File

@@ -1706,3 +1706,27 @@ def get_user_all_schedule_logs(user_id, limit=50):
LIMIT ?
''', (user_id, limit))
return [dict(row) for row in cursor.fetchall()]
def delete_schedule_logs(schedule_id, user_id):
"""删除指定定时任务的所有执行日志(需验证用户权限)"""
with db_pool.get_db() as conn:
cursor = conn.cursor()
cursor.execute('''
DELETE FROM schedule_execution_logs
WHERE schedule_id = ? AND user_id = ?
''', (schedule_id, user_id))
conn.commit()
return cursor.rowcount
def clean_old_schedule_logs(days=30):
"""清理指定天数前的定时任务执行日志"""
with db_pool.get_db() as conn:
cursor = conn.cursor()
cursor.execute('''
DELETE FROM schedule_execution_logs
WHERE execute_time < datetime('now', '-' || ? || ' days')
''', (days,))
conn.commit()
return cursor.rowcount