加入周期任务里面的每个周期的具体时间

This commit is contained in:
liuwei
2025-06-10 16:36:37 +08:00
parent 162fba12d4
commit db59c44a30

View File

@@ -85,31 +85,42 @@ def message_push_management():
@message_push_bp.route('/api/tasks', methods=['GET'])
@login_required
def api_tasks_list():
"""获取任务列表API"""
"""获取任务列表"""
try:
# 获取查询参数
status = request.args.get('status')
start_time = request.args.get('start_time')
end_time = request.args.get('end_time')
page = int(request.args.get('page', 1))
limit = int(request.args.get('limit', 20))
# 获取任务列表
db = current_app.dashboard_server.task_db
tasks, total = db.get_tasks_list(status, start_time, end_time, page, limit)
tasks = task_db.get_all_tasks()
# 处理任务数据确保所有字段都可以JSON序列化
serialized_tasks = []
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)
return jsonify({
"success": True,
"data": {
"tasks": tasks,
"total": total,
"page": page,
"limit": limit
}
'success': True,
'data': serialized_tasks
})
except Exception as e:
logger.error(f"获取任务列表失败: {e}")
return jsonify({"success": False, "error": str(e)}), 500
logger.error(f"获取任务列表失败: {str(e)}")
return jsonify({
'success': False,
'message': f'获取任务列表失败: {str(e)}'
}), 500
@message_push_bp.route('/api/tasks', methods=['POST'])