fix: give the readiness wait a timeout
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Stdio,
|
||||
thread,
|
||||
time::Duration,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use super::docker_compose;
|
||||
@@ -16,6 +16,9 @@ const CUSTOM_MAGIC: &[u8] = b"PGDMP";
|
||||
const TAR_MAGIC: &[u8] = b"toc.dat";
|
||||
const GZIP_MAGIC: &[u8] = b"\x1f\x8b";
|
||||
const CLUSTER_MARKER: &str = "PostgreSQL database cluster dump";
|
||||
const READY_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
const POLL_INTERVAL: Duration = Duration::from_secs(1);
|
||||
|
||||
// wide enough for the cluster marker, which sits a few bytes into the file
|
||||
const HEADER_LEN: usize = 512;
|
||||
|
||||
@@ -191,7 +194,10 @@ fn piped(db: &Database, script: &str, input: &Path) -> Result<std::process::Comm
|
||||
|
||||
fn wait_until_ready(db: &Database) -> Result<()> {
|
||||
debug_eprintln!("waiting until pg_isready");
|
||||
while !CommandBuilder::docker()
|
||||
let deadline = Instant::now() + READY_TIMEOUT;
|
||||
|
||||
loop {
|
||||
let ready = CommandBuilder::docker()
|
||||
.args("exec")
|
||||
.arg(&db.container)
|
||||
.args("pg_isready -U")
|
||||
@@ -202,12 +208,22 @@ fn wait_until_ready(db: &Database) -> Result<()> {
|
||||
.stdout(Stdio::null())
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.success()
|
||||
{
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
.success();
|
||||
|
||||
if ready {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
if Instant::now() >= deadline {
|
||||
bail!(
|
||||
"{} did not accept connections within {} seconds",
|
||||
db.service,
|
||||
READY_TIMEOUT.as_secs()
|
||||
);
|
||||
}
|
||||
|
||||
thread::sleep(POLL_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
fn when_ready(db: &Database, command: CommandBuilder) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user