Skip to content

Commit

Permalink
Refine output messages. Bump to 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoscout committed Sep 3, 2019
1 parent 842770f commit 8b53ac7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wait"
version = "2.5.1"
version = "2.6.0"
authors = ["ufoscout <ufoscout@gmail.com>"]
edition = "2018"

Expand Down
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ pub struct Config {
pub wait_sleep_interval: u64,
}

const LINE_SEPARATOR: &str = "--------------------------------------------------------";

pub fn wait(
sleep: &mut dyn crate::sleeper::Sleeper,
config: &Config,
on_timeout: &mut dyn FnMut(),
) {
println!("Docker-compose-wait starting with configuration:");
println!("------------------------------------------------");
println!("{}", LINE_SEPARATOR);
println!("docker-compose-wait - starting with configuration:");
println!(" - Hosts to be waiting for: [{}]", config.hosts);
println!(" - Timeout before failure: {} seconds ", config.timeout);
println!(
Expand All @@ -26,13 +28,14 @@ pub fn wait(
" - Sleeping time once all hosts are available: {} seconds",
config.wait_after
);
println!("------------------------------------------------");
println!("{}", LINE_SEPARATOR);

if config.wait_before > 0 {
println!(
"Waiting {} seconds before checking for hosts availability",
config.wait_before
);
println!("{}", LINE_SEPARATOR);
sleep.sleep(config.wait_before);
}

Expand All @@ -41,7 +44,7 @@ pub fn wait(
for host in config.hosts.trim().split(',') {
println!("Checking availability of {}", host);
while !port_check::is_port_reachable(&host.trim().to_string()) {
println!("Host {} not yet available", host);
println!("Host {} not yet available...", host);
if sleep.elapsed(config.timeout) {
println!(
"Timeout! After {} seconds some hosts are still not reachable",
Expand All @@ -52,7 +55,8 @@ pub fn wait(
}
sleep.sleep(config.wait_sleep_interval);
}
println!("Host {} is now available", host);
println!("Host {} is now available!", host);
println!("{}", LINE_SEPARATOR);
}
}

Expand All @@ -61,8 +65,12 @@ pub fn wait(
"Waiting {} seconds after hosts availability",
config.wait_after
);
println!("{}", LINE_SEPARATOR);
sleep.sleep(config.wait_after);
}

println!("docker-compose-wait - Everything's fine, the application can now start!");
println!("{}", LINE_SEPARATOR);
}

pub fn config_from_env() -> Config {
Expand Down

0 comments on commit 8b53ac7

Please sign in to comment.