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