Skip to content

Commit

Permalink
postgres waiting timeout & retry as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoBjorn committed Jan 15, 2025
1 parent 4c2ee6a commit 137c377
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compute_tools/src/bin/fast_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ mod child_stdio_to_log;
#[path = "fast_import/s3_uri.rs"]
mod s3_uri;

const PG_WAIT_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(600);
const PG_WAIT_RETRY_INTERVAL: std::time::Duration = std::time::Duration::from_secs_f32(0.3);

#[derive(clap::Parser)]
struct Args {
#[clap(long)]
Expand Down Expand Up @@ -231,12 +234,10 @@ pub(crate) async fn main() -> anyhow::Result<()> {
let restore_pg_connstring =
format!("host=localhost port=5432 user={superuser} dbname=postgres");

let timeout_duration = std::time::Duration::from_secs(600); // 10 minutes
let start_time = std::time::Instant::now();
let retry_interval = std::time::Duration::from_secs_f32(0.3);

loop {
if start_time.elapsed() > timeout_duration {
if start_time.elapsed() > PG_WAIT_TIMEOUT {
error!(
"timeout exceeded: failed to poll postgres and create database within 10 minutes"
);
Expand All @@ -261,19 +262,19 @@ pub(crate) async fn main() -> anyhow::Result<()> {
warn!(
"failed to create database: {}, retying in {}s",
e,
retry_interval.as_secs_f32()
PG_WAIT_RETRY_INTERVAL.as_secs_f32()
);
tokio::time::sleep(retry_interval).await;
tokio::time::sleep(PG_WAIT_RETRY_INTERVAL).await;
continue;
}
}
}
Err(_) => {
info!(format!(
"postgres not ready yet, retrying in {}s",
retry_interval.as_secs_f32()
PG_WAIT_RETRY_INTERVAL.as_secs_f32()
));
tokio::time::sleep(retry_interval).await;
tokio::time::sleep(PG_WAIT_RETRY_INTERVAL).await;
continue;
}
}
Expand Down

0 comments on commit 137c377

Please sign in to comment.