Skip to content

Commit b0796ca

Browse files
authored
Allow configuring dashboard connection pool settings (#635)
1 parent 0b42fcc commit b0796ca

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

pgml-dashboard/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ use guards::Cluster;
2424
use responses::{BadRequest, ResponseOk};
2525
use sqlx::Executor;
2626

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+
2734
/// This struct contains information specific to the cluster being displayed in the dashboard.
2835
///
2936
/// The dashboard is built to manage multiple clusters, but the server itself by design is stateless.
@@ -44,13 +51,18 @@ pub struct Clusters {
4451
}
4552

4653
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> {
4860
let mut pools = self.pools.lock();
4961

5062
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)
5466
.after_connect(|conn, _meta| {
5567
Box::pin(async move {
5668
conn.execute("SET application_name = 'pgml_dashboard';")

pgml-dashboard/src/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ async fn main() {
1111
dotenv::dotenv().ok();
1212

1313
let clusters = pgml_dashboard::Clusters::new();
14+
let settings = pgml_dashboard::ClustersSettings {
15+
min_connections: 0,
16+
max_connections: 5,
17+
idle_timeout: 15_000,
18+
};
19+
1420
clusters
15-
.add(-1, &pgml_dashboard::guards::default_database_url())
21+
.add(
22+
-1,
23+
&pgml_dashboard::guards::default_database_url(),
24+
settings,
25+
)
1626
.unwrap();
1727

1828
pgml_dashboard::migrate(&clusters.get(-1).unwrap())
@@ -43,6 +53,10 @@ mod test {
4353
use std::vec::Vec;
4454

4555
async fn rocket() -> Rocket<Build> {
56+
let max_connections = 5;
57+
let min_connections = 1;
58+
let idle_timeout = 15_000;
59+
4660
let clusters = Clusters::new();
4761
clusters
4862
.add(-1, &pgml_dashboard::guards::default_database_url())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy