index : git-mirror-sync.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2024-01-20 22:04:51.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2024-01-21 8:02:12.0 +00:00:00
commit
30bfeae4d25f946e5e1e54242ea706ef7f0a88c4 [patch]
tree
fac729d5a9ed8a31f801c35d3ccf8c665b036e31
parent
19d326917cf5a7010e7c5ece1051a01caf01bc87
download
30bfeae4d25f946e5e1e54242ea706ef7f0a88c4.tar.gz

feat: add graceful shutdown



Diff

 src/cli.rs  |  2 +-
 src/main.rs | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/cli.rs b/src/cli.rs
index fd5beb0..b09378c 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -5,7 +5,7 @@ use humantime::Duration;

use crate::error::ParseError;

#[derive(Debug, Parser)]
#[derive(Debug, Parser, Clone)]
pub struct CliArgs {
    /// The time to wait before refreshing repositories.
    /// eg. 10m, 60s, etc.
diff --git a/src/main.rs b/src/main.rs
index 75d3e0a..bb67a93 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,7 @@ use std::env;
use clap::Parser;
use cli::CliArgs;
use log::{error, info};
use tokio::{process::Command, time::sleep};
use tokio::{process::Command, signal, time::sleep};
use walkdir::WalkDir;

mod cli;
@@ -14,8 +14,17 @@ async fn main() {
    env::set_var("RUST_LOG", "info");
    env_logger::init();

    let args = CliArgs::parse();

    loop {
        do_sync_task(CliArgs::parse()).await
        tokio::select! {
            _ = do_sync_task(args.clone()) => {}

            _ = signal::ctrl_c() => {
                info!("Shutting down...");
                break;
            }
        }
    }
}