Skip to content

Commit

Permalink
Add option --fail-fast
Browse files Browse the repository at this point in the history
  • Loading branch information
xqm32 committed Apr 2, 2024
1 parent 4d9cf47 commit a9a050e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const DEFAULT_THRESHOLD: &str = "10 GB";
const DELETION_CHUNK_SIZE_OPTION: &str = "deletion-chunk-size";
const KEEP_OPTION: &str = "keep";
const THRESHOLD_OPTION: &str = "threshold";
const FAIL_FAST: &str = "fail-fast";

// Size threshold argument, absolute or relative to filesystem size
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -109,6 +110,7 @@ pub struct Settings {
threshold: Threshold,
keep: Option<RegexSet>,
deletion_chunk_size: usize,
fail_fast: bool,
}

// Set up the logger.
Expand Down Expand Up @@ -197,6 +199,12 @@ fn settings() -> io::Result<Settings> {
(default: {DEFAULT_DELETION_CHUNK_SIZE})",
)),
)
.arg(
Arg::with_name(FAIL_FAST)
.short("f")
.long(FAIL_FAST)
.help("Prevents restarting subprocess"),
)
.get_matches();

// Read the threshold.
Expand Down Expand Up @@ -225,10 +233,13 @@ fn settings() -> io::Result<Settings> {
None => DEFAULT_DELETION_CHUNK_SIZE,
};

let fail_fast = matches.is_present(FAIL_FAST);

Ok(Settings {
threshold,
keep,
deletion_chunk_size,
fail_fast,
})
}

Expand Down Expand Up @@ -268,6 +279,9 @@ fn main() {
loop {
if let Err(e) = run(&settings, &mut state, &mut first_run) {
error!("{}", e);
if settings.fail_fast {
break;
}
info!("Retrying in 5 seconds\u{2026}");
sleep(Duration::from_secs(5));
}
Expand Down

0 comments on commit a9a050e

Please sign in to comment.