From 48f2d4e27583776c72b1a4156c41d79536721e3c Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 1 Jan 2023 21:54:22 -0700 Subject: [PATCH] client/push: Allow setting the number of parallel uploads --- client/src/command/push.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/src/command/push.rs b/client/src/command/push.rs index 5649914..ec84475 100644 --- a/client/src/command/push.rs +++ b/client/src/command/push.rs @@ -37,6 +37,10 @@ pub struct Push { /// Ignore the upstream cache filter. #[clap(long)] ignore_upstream_cache_filter: bool, + + /// The maximum number of parallel upload processes. + #[clap(short = 'j', long, default_value = "10")] + jobs: usize, } struct PushPlan { @@ -154,6 +158,10 @@ pub async fn upload_path( pub async fn run(opts: Opts) -> Result<()> { let sub = opts.command.as_push().unwrap(); + if sub.jobs == 0 { + return Err(anyhow!("The number of jobs cannot be 0")); + } + let config = Config::load()?; let store = Arc::new(NixStore::connect()?); @@ -200,7 +208,7 @@ pub async fn run(opts: Opts) -> Result<()> { } let mp = MultiProgress::new(); - let upload_limit = Arc::new(Semaphore::new(10)); // FIXME + let upload_limit = Arc::new(Semaphore::new(sub.jobs)); let futures = plan .store_path_map .into_iter()