Up
This commit is contained in:
+24
-19
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user