Skip to content

Commit

Permalink
Merge pull request #308 from Concordium/lma/fix/pool_params
Browse files Browse the repository at this point in the history
Pool param
  • Loading branch information
lassemand authored Nov 27, 2024
2 parents 12d75a9 + e500044 commit f9aec3f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
23 changes: 16 additions & 7 deletions backend-rust/src/bin/ccdscan-api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_graphql::SDLExportOptions;
use clap::Parser;
use concordium_scan::{graphql_api, metrics};
use prometheus_client::registry::Registry;
use sqlx::PgPool;
use sqlx::postgres::PgPoolOptions;
use std::{net::SocketAddr, path::PathBuf};
use tokio::net::TcpListener;
use tokio_util::sync::CancellationToken;
Expand All @@ -16,26 +16,35 @@ struct Cli {
/// Use an environment variable when the connection contains a password, as
/// command line arguments are visible across OS processes.
#[arg(long, env = "DATABASE_URL")]
database_url: String,
database_url: String,
/// Minimum number of connections in the pool.
#[arg(long, env = "DATABASE_MIN_CONNECTIONS", default_value_t = 5)]
min_connections: u32,
/// Maximum number of connections in the pool.
#[arg(long, env = "DATABASE_MAX_CONNECTIONS", default_value_t = 10)]
max_connections: u32,
/// Output the GraphQL Schema for the API to this path.
#[arg(long)]
schema_out: Option<PathBuf>,
schema_out: Option<PathBuf>,
/// Address to listen to for API requests.
#[arg(long, env = "CCDSCAN_API_ADDRESS", default_value = "127.0.0.1:8000")]
listen: SocketAddr,
listen: SocketAddr,
/// Address to listen to for metrics requests.
#[arg(long, env = "CCDSCAN_API_METRICS_ADDRESS", default_value = "127.0.0.1:8003")]
metrics_listen: SocketAddr,
metrics_listen: SocketAddr,
#[command(flatten, next_help_heading = "Configuration")]
api_config: graphql_api::ApiServiceConfig,
api_config: graphql_api::ApiServiceConfig,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _ = dotenvy::dotenv();
let cli = Cli::parse();
tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).init();
let pool = PgPool::connect(&cli.database_url)
let pool = PgPoolOptions::new()
.min_connections(cli.min_connections)
.max_connections(cli.max_connections)
.connect(&cli.database_url)
.await
.context("Failed constructing database connection pool")?;
let cancel_token = CancellationToken::new();
Expand Down
21 changes: 15 additions & 6 deletions backend-rust/src/bin/ccdscan-indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use concordium_scan::{
metrics,
};
use prometheus_client::registry::Registry;
use sqlx::PgPool;
use sqlx::postgres::PgPoolOptions;
use std::net::SocketAddr;
use tokio::net::TcpListener;
use tokio_util::sync::CancellationToken;
Expand All @@ -20,7 +20,13 @@ struct Cli {
/// Use an environment variable when the connection contains a password, as
/// command line arguments are visible across OS processes.
#[arg(long, env = "DATABASE_URL")]
database_url: String,
database_url: String,
/// Minimum number of connections in the pool.
#[arg(long, env = "DATABASE_MIN_CONNECTIONS", default_value_t = 5)]
min_connections: u32,
/// Maximum number of connections in the pool.
#[arg(long, env = "DATABASE_MAX_CONNECTIONS", default_value_t = 10)]
max_connections: u32,
/// gRPC interface of the node. Several can be provided.
#[arg(
long,
Expand All @@ -29,20 +35,23 @@ struct Cli {
num_args = 1..,
default_value = "http://localhost:20000"
)]
node: Vec<v2::Endpoint>,
node: Vec<v2::Endpoint>,
/// Address to listen for metrics requests
#[arg(long, env = "CCDSCAN_INDEXER_METRICS_ADDRESS", default_value = "127.0.0.1:8001")]
metrics_listen: SocketAddr,
metrics_listen: SocketAddr,
#[command(flatten, next_help_heading = "Performance tuning")]
indexer_config: IndexerServiceConfig,
indexer_config: IndexerServiceConfig,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _ = dotenvy::dotenv();
let cli = Cli::parse();
tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).init();
let pool = PgPool::connect(&cli.database_url)
let pool = PgPoolOptions::new()
.min_connections(cli.min_connections)
.max_connections(cli.max_connections)
.connect(&cli.database_url)
.await
.context("Failed constructing database connection pool")?;
let cancel_token = CancellationToken::new();
Expand Down

0 comments on commit f9aec3f

Please sign in to comment.