Limit parallel network requests to CLI parameter

This commit is contained in:
FliegendeWurst 2020-04-22 12:19:12 +02:00
parent 1aca252f8c
commit 84eda01c29

View File

@ -340,7 +340,7 @@ async fn main() {
while let Some((path, obj)) = queue.pop_front() {
let ilias = Arc::clone(&ilias);
task::spawn(async {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -378,7 +378,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
path.push(item.name());
let ilias = Arc::clone(&ilias);
task::spawn(async {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -399,7 +399,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
path.push(item.name());
let ilias = Arc::clone(&ilias);
task::spawn(async {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -470,7 +470,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
};
let ilias = Arc::clone(&ilias);
task::spawn(async {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -563,7 +563,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
path.push(name);
let ilias = Arc::clone(&ilias);
task::spawn(async {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -607,7 +607,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
path.push(name);
let ilias = Arc::clone(&ilias);
task::spawn(async move {
while *TASKS_RUNNING.lock() > 1 {
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
tokio::time::delay_for(Duration::from_millis(100)).await;
}
*TASKS_RUNNING.lock() += 1;
@ -651,4 +651,8 @@ struct Opt {
/// Output directory
#[structopt(short, long, parse(from_os_str))]
output: PathBuf,
/// Parallel download jobs
#[structopt(short, long, default_value = "1")]
jobs: usize,
}