fix: 修复连接池泄漏(conn.close改为put_db) + put_db处理已关闭连接 + 添加日线同步cron
This commit is contained in:
@@ -6,7 +6,7 @@ import pandas as pd
|
||||
from datetime import datetime, timedelta
|
||||
from services.stock_service import get_stock_fund_flow, load_cached_data
|
||||
from services.stock_algorithms import get_kline_data as algo_get_kline_data
|
||||
from db import get_db
|
||||
from db import get_db, put_db
|
||||
|
||||
bp = Blueprint('market', __name__, url_prefix='/api')
|
||||
|
||||
@@ -40,7 +40,7 @@ def db_realtime_price(stock_code):
|
||||
'data': dict(row)
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/db/realtime_prices', methods=['POST'])
|
||||
@@ -71,7 +71,7 @@ def db_realtime_prices():
|
||||
'data': [dict(row) for row in rows]
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/db/fund_flow_today/<stock_code>', methods=['GET'])
|
||||
@@ -102,7 +102,7 @@ def db_fund_flow_today(stock_code):
|
||||
'data': dict(row)
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/db/fund_flow_today_batch', methods=['POST'])
|
||||
@@ -135,7 +135,7 @@ def db_fund_flow_today_batch():
|
||||
'data': [dict(row) for row in rows]
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
@bp.route('/db/data_status', methods=['GET'])
|
||||
@@ -171,7 +171,7 @@ def db_data_status():
|
||||
'recent_logs': [dict(log) for log in logs]
|
||||
})
|
||||
finally:
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
|
||||
|
||||
# ============ 原有API(兼容) ============
|
||||
@@ -305,7 +305,7 @@ def get_fund_flow_rank():
|
||||
return jsonify({'success': True, 'data': flow_data, 'total': len(flow_data),
|
||||
'source': 'cache'})
|
||||
finally:
|
||||
_conn.close()
|
||||
_put_db(conn)
|
||||
|
||||
return jsonify({'success': True, 'data': [], 'total': 0})
|
||||
except Exception as e:
|
||||
@@ -389,7 +389,7 @@ def get_fundamental(stock_code):
|
||||
'triggered_count': sig_row[2] or 0,
|
||||
}
|
||||
|
||||
conn.close()
|
||||
put_db(conn)
|
||||
except Exception as e:
|
||||
print(f"获取数据失败: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user