加入周期任务里面的每个周期的具体时间
This commit is contained in:
@@ -85,31 +85,42 @@ def message_push_management():
|
|||||||
@message_push_bp.route('/api/tasks', methods=['GET'])
|
@message_push_bp.route('/api/tasks', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def api_tasks_list():
|
def api_tasks_list():
|
||||||
"""获取任务列表API"""
|
"""获取任务列表"""
|
||||||
try:
|
try:
|
||||||
# 获取查询参数
|
tasks = task_db.get_all_tasks()
|
||||||
status = request.args.get('status')
|
# 处理任务数据,确保所有字段都可以JSON序列化
|
||||||
start_time = request.args.get('start_time')
|
serialized_tasks = []
|
||||||
end_time = request.args.get('end_time')
|
for task in tasks:
|
||||||
page = int(request.args.get('page', 1))
|
task_dict = dict(task)
|
||||||
limit = int(request.args.get('limit', 20))
|
# 处理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()
|
||||||
db = current_app.dashboard_server.task_db
|
if 'last_run_time' in task_dict and task_dict['last_run_time']:
|
||||||
tasks, total = db.get_tasks_list(status, start_time, end_time, page, limit)
|
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)
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
'success': True,
|
||||||
"data": {
|
'data': serialized_tasks
|
||||||
"tasks": tasks,
|
|
||||||
"total": total,
|
|
||||||
"page": page,
|
|
||||||
"limit": limit
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取任务列表失败: {e}")
|
logger.error(f"获取任务列表失败: {str(e)}")
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': f'获取任务列表失败: {str(e)}'
|
||||||
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
@message_push_bp.route('/api/tasks', methods=['POST'])
|
@message_push_bp.route('/api/tasks', methods=['POST'])
|
||||||
|
|||||||
Reference in New Issue
Block a user