(
url: &str,
default_timeout: Duration,
)
| 50 | } |
| 51 | |
| 52 | pub async fn postgres_client( |
| 53 | url: &str, |
| 54 | default_timeout: Duration, |
| 55 | ) -> Result<(Client, task::JoinHandle<Result<(), tokio_postgres::Error>>), anyhow::Error> { |
| 56 | let (client, connection) = Retry::default() |
| 57 | .max_duration(default_timeout) |
| 58 | .retry_async_canceling(|_| async move { |
| 59 | let pgconfig = &mut Config::from_str(url)?; |
| 60 | pgconfig.connect_timeout(default_timeout); |
| 61 | let tls = make_tls(pgconfig)?; |
| 62 | pgconfig.connect(tls).await.map_err(|e| anyhow!(e)) |
| 63 | }) |
| 64 | .await?; |
| 65 | |
| 66 | if url.contains("mzp_") { |
| 67 | println!("Connecting to PostgreSQL server at [REDACTED]..."); |
| 68 | } else { |
| 69 | println!("Connecting to PostgreSQL server at {}...", url); |
| 70 | } |
| 71 | let handle = task::spawn(|| "postgres_client_task", connection); |
| 72 | |
| 73 | Ok((client, handle)) |
| 74 | } |
no test coverage detected