Skip to content

Allow configuring dashboard connection pool settings #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pgml-dashboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ use guards::Cluster;
use responses::{BadRequest, ResponseOk};
use sqlx::Executor;

#[derive(Debug, Default, Clone)]
pub struct ClustersSettings {
pub max_connections: u32,
pub idle_timeout: u64,
pub min_connections: u32,
}

/// This struct contains information specific to the cluster being displayed in the dashboard.
///
/// The dashboard is built to manage multiple clusters, but the server itself by design is stateless.
Expand All @@ -44,13 +51,18 @@ pub struct Clusters {
}

impl Clusters {
pub fn add(&self, cluster_id: i64, database_url: &str) -> anyhow::Result<PgPool> {
pub fn add(
&self,
cluster_id: i64,
database_url: &str,
settings: ClustersSettings,
) -> anyhow::Result<PgPool> {
let mut pools = self.pools.lock();

let pool = PgPoolOptions::new()
.max_connections(5)
.idle_timeout(std::time::Duration::from_millis(15_000))
.min_connections(0)
.max_connections(settings.max_connections)
.idle_timeout(std::time::Duration::from_millis(settings.idle_timeout))
.min_connections(settings.min_connections)
.after_connect(|conn, _meta| {
Box::pin(async move {
conn.execute("SET application_name = 'pgml_dashboard';")
Expand Down
16 changes: 15 additions & 1 deletion pgml-dashboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ async fn main() {
dotenv::dotenv().ok();

let clusters = pgml_dashboard::Clusters::new();
let settings = pgml_dashboard::ClustersSettings {
min_connections: 0,
max_connections: 5,
idle_timeout: 15_000,
};

clusters
.add(-1, &pgml_dashboard::guards::default_database_url())
.add(
-1,
&pgml_dashboard::guards::default_database_url(),
settings,
)
.unwrap();

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

async fn rocket() -> Rocket<Build> {
let max_connections = 5;
let min_connections = 1;
let idle_timeout = 15_000;

let clusters = Clusters::new();
clusters
.add(-1, &pgml_dashboard::guards::default_database_url())
Expand Down
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