diff --git a/admin/dashboard/blueprints/message_push.py b/admin/dashboard/blueprints/message_push.py index 91101db..3673c19 100644 --- a/admin/dashboard/blueprints/message_push.py +++ b/admin/dashboard/blueprints/message_push.py @@ -98,34 +98,15 @@ def api_tasks_list(): db = current_app.dashboard_server.task_db tasks, total = db.get_tasks_list(status, start_time, end_time, page, limit) - # 处理任务数据,确保所有字段都可以JSON序列化 - serialized_tasks = [] + # 处理recurring_time序列化问题 for task in tasks: - task_dict = dict(task) - # 处理timedelta对象 - if 'next_schedule_time' in task_dict and task_dict['next_schedule_time']: - task_dict['next_schedule_time'] = task_dict['next_schedule_time'].isoformat() - if 'last_run_time' in task_dict and task_dict['last_run_time']: - task_dict['last_run_time'] = task_dict['last_run_time'].isoformat() - if 'recurring_end' in task_dict and task_dict['recurring_end']: - task_dict['recurring_end'] = task_dict['recurring_end'].isoformat() - # 处理JSON字符串 - if 'content_link' in task_dict and task_dict['content_link']: - try: - task_dict['content_link'] = json.loads(task_dict['content_link']) - except: - task_dict['content_link'] = None - if 'weekly_days' in task_dict and task_dict['weekly_days']: - try: - task_dict['weekly_days'] = json.loads(task_dict['weekly_days']) - except: - task_dict['weekly_days'] = None - serialized_tasks.append(task_dict) + if hasattr(task, 'recurring_time') and task.recurring_time: + task.recurring_time = task.recurring_time.isoformat() return jsonify({ "success": True, "data": { - "tasks": serialized_tasks, + "tasks": tasks, "total": total, "page": page, "limit": limit @@ -133,10 +114,7 @@ def api_tasks_list(): }) except Exception as e: logger.error(f"获取任务列表失败: {str(e)}") - return jsonify({ - "success": False, - "message": f'获取任务列表失败: {str(e)}' - }), 500 + return jsonify({"success": False, "error": str(e)}), 500 @message_push_bp.route('/api/tasks', methods=['POST'])