Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
levkk merged 1 commit intomasterfromlevkk-longer-conns
May 18, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionspgml-dashboard/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionpgml-dashboard/src/main.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp