Skip to content

Commit

Permalink
make max retry configurable via env
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Nov 6, 2024
1 parent 5f1d06c commit 079dab5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion block-index/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ impl AppState {
.parse::<usize>()
.unwrap_or(8_usize);

let max_conn_retries = env::var("DATABASE_MAX_CONN_RETRIES")
.unwrap_or_else(|_| 5.to_string())
.parse::<u32>()
.unwrap_or(5);

let pool = tryhard::retry_fn(|| async {
let pool_manager = deadpool_diesel::Manager::from_config(
db_url.clone(),
Expand All @@ -30,7 +35,7 @@ impl AppState {
.build()
.context("Failed to build Postgres db pool")
})
.retries(5)
.retries(max_conn_retries)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(5))
.await?;
Expand Down
7 changes: 6 additions & 1 deletion chain/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ impl AppState {
.parse::<usize>()
.unwrap_or(8_usize);

let max_conn_retries = env::var("DATABASE_MAX_CONN_RETRIES")
.unwrap_or_else(|_| 5.to_string())
.parse::<u32>()
.unwrap_or(5);

let pool = tryhard::retry_fn(|| async {
let pool_manager = deadpool_diesel::Manager::from_config(
db_url.clone(),
Expand All @@ -30,7 +35,7 @@ impl AppState {
.build()
.context("Failed to build Postgres db pool")
})
.retries(5)
.retries(max_conn_retries)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(5))
.await?;
Expand Down
7 changes: 6 additions & 1 deletion webserver/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ impl AppState {
.parse::<usize>()
.unwrap_or(8_usize);

let max_conn_retries = env::var("DATABASE_MAX_CONN_RETRIES")
.unwrap_or_else(|_| 5.to_string())
.parse::<u32>()
.unwrap_or(5);

let pool = tryhard::retry_fn(|| async {
let pool_manager = deadpool_diesel::Manager::from_config(
db_url.clone(),
Expand All @@ -30,7 +35,7 @@ impl AppState {
.build()
.context("Failed to build Postgres db pool")
})
.retries(5)
.retries(max_conn_retries)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(5))
.await?;
Expand Down

0 comments on commit 079dab5

Please sign in to comment.