Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flag to exit immediately on error instead of retrying #297

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ Here are the supported command-line options:

```
USAGE:
docuum
docuum [OPTIONS]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the output of docuum --help change here with the introduction of the new flag? (Is this clap's behavior?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clap says1:

The default is that the auto-generated help message will group flags, and options separately.

Maybe the flag --fast-fail makes clap reorganize the help information.

Footnotes

  1. https://docs.rs/clap/2.34.0/clap/enum.AppSettings.html#variant.UnifiedHelpMessage


OPTIONS:
-d, --deletion-chunk-size <DELETION CHUNK SIZE>
Removes specified quantity of images at a time (default: 1)

-f, --fail-fast
Exits immediately on error instead of retrying

-h, --help
Prints help information

Expand Down
25 changes: 22 additions & 3 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("Exits immediately on error instead of retrying"),
)
.get_matches();

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

// Determine whether to exit immediately on error.
let fail_fast = matches.is_present(FAIL_FAST);

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

Expand Down Expand Up @@ -264,12 +276,19 @@ fn main() {
|state| (state, false),
);

// Stream Docker events and vacuum when necessary. Restart if an error occurs.
// Stream Docker events and vacuum when necessary.
loop {
if let Err(e) = run(&settings, &mut state, &mut first_run) {
error!("{}", e);
info!("Retrying in 5 seconds\u{2026}");
sleep(Duration::from_secs(5));
// If we're in fail-fast mode, exit immediately.
if settings.fail_fast {
error!("Exiting due to --fail-fast");
exit(1);
// Otherwise, retry after a short delay.
} else {
error!("Retrying in 5 seconds\u{2026}");
sleep(Duration::from_secs(5));
}
}
}
}
Loading