Skip to content

Commit

Permalink
fix: add workaround for Railway Private Networking delay
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiDood committed Dec 20, 2023
1 parent 70ccf2b commit 7e8ad38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ features = ["http1", "server"]
[dependencies.tokio]
version = "1.27"
default-features = false
features = ["macros", "rt-multi-thread", "signal"]
features = ["macros", "rt-multi-thread", "signal", "time"]

[profile.release]
lto = true
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ fn main() -> anyhow::Result<()> {
};

runtime.block_on(async {
let (client, connection) = loop {
// HACK: Railway Private Networking requires 100ms to set up.
let err = match config.connect(api::NoTls).await {
Ok(pair) => break pair,
Err(err) => err,
};
log::error!("{err}");
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
};

use core::pin::pin;
let (client, connection) = config.connect(api::NoTls).await?;
let mut postgres = pin!(runtime.spawn(connection));
log::info!("PostgreSQL driver connected");

Expand Down

0 comments on commit 7e8ad38

Please sign in to comment.