diff --git a/src/utils/database-common/src/plugins/mysql_plugin.rs b/src/utils/database-common/src/plugins/mysql_plugin.rs index b670c5303..890f48ba8 100644 --- a/src/utils/database-common/src/plugins/mysql_plugin.rs +++ b/src/utils/database-common/src/plugins/mysql_plugin.rs @@ -7,10 +7,13 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0. +use std::time::Duration; + use dill::*; use secrecy::ExposeSecret; use sqlx::mysql::MySqlConnectOptions; -use sqlx::MySqlPool; +use sqlx::pool::PoolOptions; +use sqlx::{MySql, MySqlPool}; use crate::*; @@ -58,7 +61,20 @@ impl MySqlPlugin { .password(db_credentials.password.expose_secret()); } - MySqlPool::connect_lazy_with(mysql_options) + let mysql_pool: PoolOptions = PoolOptions::new() + .max_lifetime( + db_connection_settings + .max_lifetime_secs + .map(Duration::from_secs), + ) + .max_connections(db_connection_settings.max_connections.unwrap_or(10)) + .acquire_timeout( + db_connection_settings + .acquire_timeout_secs + .map_or(Duration::from_secs(30), Duration::from_secs), + ); + + mysql_pool.connect_lazy_with(mysql_options) } }