修复定时任务日志500错误
问题原因: - SQL查询中使用AS别名在SQLite Row对象转换时可能失败 修复方案: - 改为查询所有字段后在Python中进行字段映射 - 添加字段映射:execute_time → created_at - 添加字段映射:success_accounts → success_count - 添加字段映射:failed_accounts → failed_count - 添加字段映射:duration_seconds → duration 位置: database.py 第1661-1683行 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
31
database.py
31
database.py
@@ -1663,27 +1663,24 @@ def get_schedule_execution_logs(schedule_id, limit=10):
|
||||
with db_pool.get_db() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
SELECT
|
||||
id,
|
||||
schedule_id,
|
||||
user_id,
|
||||
schedule_name,
|
||||
execute_time as created_at,
|
||||
total_accounts,
|
||||
success_accounts as success_count,
|
||||
failed_accounts as failed_count,
|
||||
total_items,
|
||||
total_attachments,
|
||||
total_screenshots,
|
||||
duration_seconds as duration,
|
||||
status,
|
||||
error_message
|
||||
FROM schedule_execution_logs
|
||||
SELECT * FROM schedule_execution_logs
|
||||
WHERE schedule_id = ?
|
||||
ORDER BY execute_time DESC
|
||||
LIMIT ?
|
||||
''', (schedule_id, limit))
|
||||
return [dict(row) for row in cursor.fetchall()]
|
||||
|
||||
# 将数据库字段映射到前端期望的字段名
|
||||
logs = []
|
||||
for row in cursor.fetchall():
|
||||
log = dict(row)
|
||||
# 字段映射
|
||||
log['created_at'] = log.get('execute_time')
|
||||
log['success_count'] = log.get('success_accounts', 0)
|
||||
log['failed_count'] = log.get('failed_accounts', 0)
|
||||
log['duration'] = log.get('duration_seconds', 0)
|
||||
logs.append(log)
|
||||
|
||||
return logs
|
||||
|
||||
|
||||
def get_user_all_schedule_logs(user_id, limit=50):
|
||||
|
||||
Reference in New Issue
Block a user