|
|
|
@ -1,10 +1,18 @@
|
|
|
|
|
import mysql.connector
|
|
|
|
|
from AiService.Config.Config import *
|
|
|
|
|
import mysql.connector.pooling
|
|
|
|
|
|
|
|
|
|
class TaskModel:
|
|
|
|
|
# 创建连接池
|
|
|
|
|
connection_pool = mysql.connector.pooling.MySQLConnectionPool(
|
|
|
|
|
pool_name="task_pool",
|
|
|
|
|
pool_size=5, # 连接池大小
|
|
|
|
|
**MYSQL_CONFIG
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
# 初始化 MySQL 连接
|
|
|
|
|
self.connection = mysql.connector.connect(**MYSQL_CONFIG)
|
|
|
|
|
# 从连接池获取连接
|
|
|
|
|
self.connection = self.connection_pool.get_connection()
|
|
|
|
|
self.cursor = self.connection.cursor()
|
|
|
|
|
|
|
|
|
|
def insert_task(self, task_id: str, keyword: str):
|
|
|
|
@ -24,7 +32,7 @@ class TaskModel:
|
|
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
|
"""
|
|
|
|
|
关闭 MySQL 连接
|
|
|
|
|
将连接归还到连接池
|
|
|
|
|
"""
|
|
|
|
|
self.cursor.close()
|
|
|
|
|
self.connection.close()
|
|
|
|
|
self.connection.close()
|