"stop" handling
This commit is contained in:
parent
e8709b79ce
commit
f63f1c870e
1 changed files with 9 additions and 12 deletions
21
src/main.rs
21
src/main.rs
|
|
@ -18,11 +18,14 @@ use appstate::AppState;
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let stop = Arc::new(AtomicBool::new(false));
|
||||||
let r = running.clone();
|
|
||||||
|
|
||||||
ctrlc::set_handler(move || r.store(false, Ordering::SeqCst))
|
let stop_ctrlc = stop.clone();
|
||||||
.expect("Error setting Ctrl-C handler");
|
ctrlc::set_handler(move || {
|
||||||
|
stop_ctrlc.store(true, Ordering::SeqCst);
|
||||||
|
info!("stopping after chunk ...");
|
||||||
|
})
|
||||||
|
.expect("Error setting Ctrl-C handler");
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
|
@ -36,10 +39,7 @@ fn main() {
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let mut state = match AppState::try_resume(&args) {
|
let mut state = match AppState::try_resume(&args) {
|
||||||
Some(state) => {
|
Some(state) => state,
|
||||||
info!("loaded state: {state:?}");
|
|
||||||
state
|
|
||||||
}
|
|
||||||
None => AppState::from_args(&args, &agent).unwrap_or_else(|e| {
|
None => AppState::from_args(&args, &agent).unwrap_or_else(|e| {
|
||||||
error!("could not create new state: {e}");
|
error!("could not create new state: {e}");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
@ -58,10 +58,7 @@ fn main() {
|
||||||
|
|
||||||
state.save().unwrap();
|
state.save().unwrap();
|
||||||
|
|
||||||
if !running.load(Ordering::SeqCst) {
|
stop.load(Ordering::SeqCst).then(|| exit(0));
|
||||||
info!("terminating ...");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("uploads done");
|
info!("uploads done");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue