Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Jul 19, 2023
2 parents ed936ee + 62f8c75 commit 4f28556
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
21 changes: 11 additions & 10 deletions nexus/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use pt::{
peerdb_peers::{peer::Config, DbType, Peer},
};
use tokio_postgres::{types, Client};
use urlencoding::encode;

mod embedded {
use refinery::embed_migrations;
Expand Down Expand Up @@ -76,20 +77,20 @@ impl CatalogConfig {

// Get the connection string for this catalog configuration
pub fn get_connection_string(&self) -> String {
let mut connection_string = String::new();
connection_string.push_str("host=");
connection_string.push_str(&self.host);
connection_string.push_str(" port=");
connection_string.push_str(&self.port.to_string());
connection_string.push_str(" user=");
let mut connection_string = String::from("postgres://");

connection_string.push_str(&self.user);
if !self.password.is_empty() {
connection_string.push_str(" password=");
let encoded_password = urlencoding::encode(&self.password);
connection_string.push_str(&encoded_password);
connection_string.push(':');
connection_string.push_str(&encode(&self.password));
}
connection_string.push_str(" dbname=");
connection_string.push('@');
connection_string.push_str(&self.host);
connection_string.push(':');
connection_string.push_str(&self.port.to_string());
connection_string.push('/');
connection_string.push_str(&self.database);

connection_string
}
}
Expand Down
25 changes: 13 additions & 12 deletions nexus/peer-postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ pub struct PostgresQueryExecutor {
}

fn get_connection_string(config: &PostgresConfig) -> String {
let mut connection_string = String::new();
connection_string.push_str("host=");
connection_string.push_str(&config.host);
connection_string.push_str(" port=");
connection_string.push_str(&config.port.to_string());
connection_string.push_str(" user=");
let mut connection_string = String::from("postgres://");

connection_string.push_str(&config.user);
if !config.password.is_empty() {
connection_string.push_str(" password=");
let encoded_password = urlencoding::encode(&config.password);
connection_string.push_str(&encoded_password);
connection_string.push(':');
connection_string.push_str(&urlencoding::encode(&config.password));
}
connection_string.push_str(" dbname=");
connection_string.push('@');
connection_string.push_str(&config.host);
connection_string.push(':');
connection_string.push_str(&config.port.to_string());
connection_string.push('/');
connection_string.push_str(&config.database);
connection_string.push_str(" connect_timeout=");
connection_string.push_str("15");

// Add the timeout as a query parameter
connection_string.push_str("?connect_timeout=15");

connection_string
}

Expand Down
2 changes: 1 addition & 1 deletion nexus/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ async fn run_migrations(config: &CatalogConfig) -> anyhow::Result<()> {
}
Err(err) => {
tracing::warn!(
"Failed to connect to catalog. Retrying in 30 seconds. {}",
"Failed to connect to catalog. Retrying in 30 seconds. {:?}",
err
);
tokio::time::sleep(Duration::from_secs(30)).await;
Expand Down

0 comments on commit 4f28556

Please sign in to comment.