Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn run(args: Args) -> i32 {
])
.expect("error: could not create signal stream");

let log_failed_attempt = make_error_logger(args.quiet);
let log = make_logger(args.quiet);

while num_attempts < args.attempts {
let spawn = Command::new(&args.command[0])
Expand Down Expand Up @@ -78,7 +78,7 @@ async fn run(args: Args) -> i32 {
break;
}

log_failed_attempt(format!(
log(format!(
"command `{}` exited with non-zero code ({}) while handling stop signal",
args.command.join(" "),
code
Expand All @@ -103,7 +103,7 @@ async fn run(args: Args) -> i32 {
num_attempts += 1;

if num_attempts < args.attempts {
log_failed_attempt(format!(
log(format!(
"command `{}` exited with non-zero code ({}) on attempt #{}; retrying in {}",
args.command.join(" "),
last_exit_code,
Expand All @@ -116,6 +116,7 @@ async fn run(args: Args) -> i32 {

tokio::select! {
Some(_signal) = signals.next() => {
log(format!("received stop signal during sleep; exiting before attempt #{}", num_attempts + 1));
return last_exit_code;
}
_ = &mut backoff_sleep => {}
Expand All @@ -125,7 +126,7 @@ async fn run(args: Args) -> i32 {
}
}

log_failed_attempt(format!(
log(format!(
"command `{}` exited with non-zero code ({}) on attempt #{}; maximum attempts reached",
args.command.join(" "),
last_exit_code,
Expand All @@ -135,7 +136,7 @@ async fn run(args: Args) -> i32 {
last_exit_code
}

fn make_error_logger(quiet: bool) -> impl Fn(String) {
fn make_logger(quiet: bool) -> impl Fn(String) {
if quiet {
|_msg| {}
} else {
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ wait ${processId} 2>/dev/null
assertEqual \
"No further attempts occur when the child exits non-zero and a stop signal is received" \
"${outputBeforeStop}" \
"$(cat ./output)"
"$(grep -v 'received stop signal during sleep' ./output)"

#
# Given: The child is running,
Expand Down
Loading