This commit is contained in:
Ryan
2026-08-10 21:00:22 -04:00
parent 89d93a5a20
commit 1540e30be5
3 changed files with 27 additions and 24 deletions
+24 -19
View File
@@ -33,25 +33,30 @@ class DBConnector:
pool_min: int = 5,
pool_recycle: int = 3600,
):
self._pool = PooledDB(
creator=pymysql,
maxconnections=pool_size,
mincached=pool_min,
maxcached=pool_size,
maxusage=200,
blocking=True,
max_idle_time=pool_recycle,
connection_timeout=10,
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor,
host=host,
port=port,
database=database,
user=user,
password=password,
read_timeout=30,
write_timeout=30,
)
# PooledDB parameters
pool_config = {
"creator": pymysql,
"maxconnections": pool_size,
"mincached": pool_min,
"maxcached": pool_size,
"maxusage": 200,
"blocking": True,
}
# PyMySQL connection parameters
connection_params = {
"host": host,
"port": port,
"database": database,
"user": user,
"password": password,
"charset": "utf8mb4",
"cursorclass": pymysql.cursors.DictCursor,
"read_timeout": 30,
"write_timeout": 30,
}
self._pool = PooledDB(**pool_config, **connection_params)
logger.info(
"DB pool initialized: host=%s db=%s pool_size=%d min=%d",
host, database, pool_size, pool_min,