diff --git a/Cargo.toml b/Cargo.toml index d801f60..1d109df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ rand = { default-features = false, version = "0.8.5" } futures-util = { version = "0.3", default-features = false, features = ["std"] } sqlx = { version = "0.7.4", features = [ "runtime-tokio", "postgres", "macros", "chrono"] } sqlx-pgrow-serde = "0.2.0" -tokio-retry = "0.3" +tryhard = "0.5" # Logging tracing = { version = "0.1.37", default_features = false } diff --git a/src/db.rs b/src/db.rs index 82642a3..80c2416 100644 --- a/src/db.rs +++ b/src/db.rs @@ -3,10 +3,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use sqlx::{postgres::PgPoolOptions, postgres::PgRow, PgPool}; use sqlx_pgrow_serde::SerMapPgRow; -use std::collections::HashMap; +use std::{collections::HashMap, time::Duration}; use tracing::{warn, info, debug}; -use tokio_retry::strategy::{ExponentialBackoff, jitter}; -use tokio_retry::Retry; #[derive(Serialize, Deserialize, Debug, Default, Clone)] @@ -19,11 +17,7 @@ include!(concat!(env!("OUT_DIR"), "/sql_replace_map.rs")); pub async fn get_pg_connection_pool(pg_url: &str, max_attempts: u32) -> Result { info!("Trying to establish a PostgreSQL connection pool"); - let retry_strategy = ExponentialBackoff::from_millis(1000) - .map(jitter) - .take(max_attempts as usize); - - let result = Retry::spawn(retry_strategy, || async { + tryhard::retry_fn(|| async { info!("Attempting to connect to PostgreSQL"); PgPoolOptions::new() .max_connections(10) @@ -33,9 +27,10 @@ pub async fn get_pg_connection_pool(pg_url: &str, max_attempts: u32) -> Result