Add indexer case to avoid 0 max_database_connection (#4073)

This commit is contained in:
wendrul
2024-07-13 00:18:56 +02:00
committed by GitHub
parent 88ae5e89db
commit 0a886e09ef
2 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -259,7 +259,7 @@ async fn windmill_main() -> anyhow::Result<()> {
};
tracing::info!("Connecting to database...");
let db = windmill_common::connect_db(server_mode).await?;
let db = windmill_common::connect_db(server_mode, indexer_mode).await?;
tracing::info!("Database connected");
let num_version = sqlx::query_scalar!("SELECT version()").fetch_one(&db).await;
+15 -7
View File
@@ -47,6 +47,7 @@ pub mod tracing_init;
pub const DEFAULT_MAX_CONNECTIONS_SERVER: u32 = 50;
pub const DEFAULT_MAX_CONNECTIONS_WORKER: u32 = 5;
pub const DEFAULT_MAX_CONNECTIONS_INDEXER: u32 = 5;
pub const DEFAULT_HUB_BASE_URL: &str = "https://hub.windmill.dev";
@@ -185,7 +186,10 @@ async fn reset() -> () {
todo!()
}
pub async fn connect_db(server_mode: bool) -> anyhow::Result<sqlx::Pool<sqlx::Postgres>> {
pub async fn connect_db(
server_mode: bool,
indexer_mode: bool,
) -> anyhow::Result<sqlx::Pool<sqlx::Postgres>> {
use anyhow::Context;
use std::env::var;
use tokio::fs::File;
@@ -211,12 +215,16 @@ pub async fn connect_db(server_mode: bool) -> anyhow::Result<sqlx::Pool<sqlx::Po
if server_mode {
DEFAULT_MAX_CONNECTIONS_SERVER
} else {
DEFAULT_MAX_CONNECTIONS_WORKER
* std::env::var("NUM_WORKERS")
.ok()
.map(|x| x.parse().ok())
.flatten()
.unwrap_or(1)
if indexer_mode {
DEFAULT_MAX_CONNECTIONS_INDEXER
} else {
DEFAULT_MAX_CONNECTIONS_WORKER
* std::env::var("NUM_WORKERS")
.ok()
.map(|x| x.parse().ok())
.flatten()
.unwrap_or(1)
}
}
}
};