@@ -24,6 +24,13 @@ use guards::Cluster;
24
24
use responses:: { BadRequest , ResponseOk } ;
25
25
use sqlx:: Executor ;
26
26
27
+ #[ derive( Debug , Default , Clone ) ]
28
+ pub struct ClustersSettings {
29
+ pub max_connections : u32 ,
30
+ pub idle_timeout : u64 ,
31
+ pub min_connections : u32 ,
32
+ }
33
+
27
34
/// This struct contains information specific to the cluster being displayed in the dashboard.
28
35
///
29
36
/// The dashboard is built to manage multiple clusters, but the server itself by design is stateless.
@@ -44,13 +51,18 @@ pub struct Clusters {
44
51
}
45
52
46
53
impl Clusters {
47
- pub fn add ( & self , cluster_id : i64 , database_url : & str ) -> anyhow:: Result < PgPool > {
54
+ pub fn add (
55
+ & self ,
56
+ cluster_id : i64 ,
57
+ database_url : & str ,
58
+ settings : ClustersSettings ,
59
+ ) -> anyhow:: Result < PgPool > {
48
60
let mut pools = self . pools . lock ( ) ;
49
61
50
62
let pool = PgPoolOptions :: new ( )
51
- . max_connections ( 5 )
52
- . idle_timeout ( std:: time:: Duration :: from_millis ( 15_000 ) )
53
- . min_connections ( 0 )
63
+ . max_connections ( settings . max_connections )
64
+ . idle_timeout ( std:: time:: Duration :: from_millis ( settings . idle_timeout ) )
65
+ . min_connections ( settings . min_connections )
54
66
. after_connect ( |conn, _meta| {
55
67
Box :: pin ( async move {
56
68
conn. execute ( "SET application_name = 'pgml_dashboard';" )
0 commit comments