为memory添加ttl,启动定时清理
This commit is contained in:
		| @@ -3,7 +3,7 @@ import logging | ||||
|  | ||||
| import util.utils | ||||
| from logging_config import LOGGING_CONFIG | ||||
| from service.cus_vanna_srevice import CustomVanna, QdrantClient | ||||
| from service.cus_vanna_srevice import CustomVanna, QdrantClient, TTLCacheWrapper | ||||
| from decouple import config | ||||
| import flask | ||||
| from util import load_ddl_doc | ||||
| @@ -67,6 +67,7 @@ def init_vn(vn): | ||||
| from vanna.flask import VannaFlaskApp | ||||
| vn = create_vana() | ||||
| app = VannaFlaskApp(vn,chart=False) | ||||
| app.cache = TTLCacheWrapper(app.cache, ttl = config('TTL_CACHE', cast=int)) | ||||
| init_vn(vn) | ||||
| cache = app.cache | ||||
| @app.flask_app.route("/yj_sqlbot/api/v0/generate_sql_2", methods=["GET"]) | ||||
| @@ -119,7 +120,7 @@ def generate_sql_2(): | ||||
|  | ||||
| @app.flask_app.route("/yj_sqlbot/api/v0/run_sql_2", methods=["GET"]) | ||||
| @app.requires_cache(["sql"]) | ||||
| def run_sql_2(id: str, sql: str): | ||||
| def run_sql_2(id: str, sql: str, page_num=None, page_size=None): | ||||
|     """ | ||||
|     Run SQL | ||||
|     --- | ||||
| @@ -155,6 +156,9 @@ def run_sql_2(id: str, sql: str): | ||||
|                 } | ||||
|             ) | ||||
|  | ||||
|         # count_sql = f"SELECT COUNT(*) AS total_count FROM ({sql}) AS subquery" | ||||
|         # df_count = vn.run_sql(count_sql) | ||||
|         # total_count = df_count[0]["total_count"] if df_count is not None else 0 | ||||
|         df = vn.run_sql(sql=sql) | ||||
|         logger.info("") | ||||
|         app.cache.set(id=id, field="df", value=df) | ||||
| @@ -162,6 +166,7 @@ def run_sql_2(id: str, sql: str): | ||||
|         logger.info("df ---------------{0}   {1}".format(result,type(result))) | ||||
|         # result = util.utils.deal_result(data=result) | ||||
|  | ||||
|  | ||||
|         return jsonify( | ||||
|             { | ||||
|                 "type": "success", | ||||
| @@ -174,6 +179,8 @@ def run_sql_2(id: str, sql: str): | ||||
|         logger.error(f"run sql failed:{e}") | ||||
|         return jsonify({"type": "sql_error", "error": str(e)}) | ||||
|  | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|  | ||||
|     app.run(host='0.0.0.0', port=8084, debug=False) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 yujj128
					yujj128