From a893a41c90d3c3c0c5e3a0b2e64a075902207e09 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 13 Jul 2023 11:32:48 -0700 Subject: [PATCH] rename get to connect --- web3_proxy/src/app/mod.rs | 4 ++-- web3_proxy/src/bin/web3_proxy_cli.rs | 20 ++++++++++---------- web3_proxy/src/relational_db.rs | 6 ++++-- web3_proxy/src/sub_commands/search_kafka.rs | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 462b5a59..256429e1 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -12,7 +12,7 @@ use crate::jsonrpc::{ JsonRpcErrorData, JsonRpcForwardedResponse, JsonRpcForwardedResponseEnum, JsonRpcId, JsonRpcParams, JsonRpcRequest, JsonRpcRequestEnum, JsonRpcResultData, }; -use crate::relational_db::{get_db, get_migrated_db, DatabaseConnection, DatabaseReplica}; +use crate::relational_db::{connect_db, get_migrated_db, DatabaseConnection, DatabaseReplica}; use crate::response_cache::{ JsonRpcQueryCacheKey, JsonRpcResponseCache, JsonRpcResponseEnum, JsonRpcResponseWeigher, }; @@ -245,7 +245,7 @@ impl Web3ProxyApp { .db_replica_max_connections .unwrap_or(db_max_connections); - let db_replica = get_db( + let db_replica = connect_db( db_replica_url, db_replica_min_connections, db_replica_max_connections, diff --git a/web3_proxy/src/bin/web3_proxy_cli.rs b/web3_proxy/src/bin/web3_proxy_cli.rs index 5ac7a353..2958049d 100644 --- a/web3_proxy/src/bin/web3_proxy_cli.rs +++ b/web3_proxy/src/bin/web3_proxy_cli.rs @@ -18,7 +18,7 @@ use web3_proxy::sub_commands; use web3_proxy::{ app::APP_USER_AGENT, config::TopConfig, - relational_db::{get_db, get_migrated_db}, + relational_db::{connect_db, get_migrated_db}, }; #[cfg(feature = "mimalloc")] @@ -307,7 +307,7 @@ fn main() -> anyhow::Result<()> { "'--config' (with a db) or '--db-url' is required to run change_admin_status", ); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -316,7 +316,7 @@ fn main() -> anyhow::Result<()> { .db_url .expect("'--config' (with a db) or '--db-url' is required to run change_user_addres"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -325,7 +325,7 @@ fn main() -> anyhow::Result<()> { .db_url .expect("'--config' (with a db) or '--db-url' is required to run change_user_tier"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -334,7 +334,7 @@ fn main() -> anyhow::Result<()> { "'--config' (with a db) or '--db-url' is required to run change_user_tier_by_address", ); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -343,7 +343,7 @@ fn main() -> anyhow::Result<()> { .db_url .expect("'--config' (with a db) or '--db-url' is required to run change_user_tier_by_key"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -371,7 +371,7 @@ fn main() -> anyhow::Result<()> { .db_url .expect("'--config' (with a db) or '--db-url' is required to run count_users"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -388,7 +388,7 @@ fn main() -> anyhow::Result<()> { .expect("'--config' (with a db) or '--db-url' is required to run drop_migration_lock"); // very intentionally, do NOT run migrations here. that would wait forever if the migration lock is abandoned - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } @@ -402,7 +402,7 @@ fn main() -> anyhow::Result<()> { .db_url .expect("'--config' (with a db) or '--db-url' is required to run the migration from stats-mysql to stats-influx"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(top_config, &db_conn).await } SubCommand::Pagerduty(x) => { @@ -434,7 +434,7 @@ fn main() -> anyhow::Result<()> { let db_url = cli_config .db_url .expect("'--config' (with a db) or '--db-url' is required to run transfer_key"); - let db_conn = get_db(db_url, 1, 1).await?; + let db_conn = connect_db(db_url, 1, 1).await?; x.main(&db_conn).await } diff --git a/web3_proxy/src/relational_db.rs b/web3_proxy/src/relational_db.rs index ed2aff29..a4874b14 100644 --- a/web3_proxy/src/relational_db.rs +++ b/web3_proxy/src/relational_db.rs @@ -22,7 +22,7 @@ impl AsRef for DatabaseReplica { } } -pub async fn get_db( +pub async fn connect_db( db_url: String, min_connections: u32, max_connections: u32, @@ -33,10 +33,12 @@ pub async fn get_db( let mut db_opt = sea_orm::ConnectOptions::new(db_url); // TODO: load all these options from the config file. i think docker mysql default max is 100 + // Amazon RDS Proxy default idle timeout is 1800 seconds // TODO: sqlx info logging is way too verbose for production. db_opt .acquire_timeout(Duration::from_secs(5)) .connect_timeout(Duration::from_secs(5)) + .idle_timeout(Duration::from_secs(1795)) .min_connections(min_connections) .max_connections(max_connections) .sqlx_logging_level(tracing::log::LevelFilter::Trace) @@ -121,7 +123,7 @@ pub async fn get_migrated_db( max_connections: u32, ) -> anyhow::Result { // TODO: this seems to fail silently - let db_conn = get_db(db_url, min_connections, max_connections) + let db_conn = connect_db(db_url, min_connections, max_connections) .await .context("getting db")?; diff --git a/web3_proxy/src/sub_commands/search_kafka.rs b/web3_proxy/src/sub_commands/search_kafka.rs index 0c53c861..f0445195 100644 --- a/web3_proxy/src/sub_commands/search_kafka.rs +++ b/web3_proxy/src/sub_commands/search_kafka.rs @@ -1,4 +1,4 @@ -use crate::{config::TopConfig, frontend::authorization::RpcSecretKey, relational_db::get_db}; +use crate::{config::TopConfig, frontend::authorization::RpcSecretKey, relational_db::connect_db}; use anyhow::Context; use argh::FromArgs; use entities::rpc_key; @@ -35,7 +35,7 @@ impl SearchKafkaSubCommand { let mut rpc_key_id = self.rpc_key_id.map(|x| x.get()); if let Some(rpc_key) = self.rpc_key { - let db_conn = get_db(top_config.app.db_url.unwrap(), 1, 1).await?; + let db_conn = connect_db(top_config.app.db_url.unwrap(), 1, 1).await?; let rpc_key: Uuid = rpc_key.into();