mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Limit parallel network requests to CLI parameter
This commit is contained in:
parent
1aca252f8c
commit
84eda01c29
16
src/main.rs
16
src/main.rs
@ -340,7 +340,7 @@ async fn main() {
|
|||||||
while let Some((path, obj)) = queue.pop_front() {
|
while let Some((path, obj)) = queue.pop_front() {
|
||||||
let ilias = Arc::clone(&ilias);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async {
|
task::spawn(async {
|
||||||
while *TASKS_RUNNING.lock() > 1 {
|
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
|
||||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*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());
|
path.push(item.name());
|
||||||
let ilias = Arc::clone(&ilias);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async {
|
task::spawn(async {
|
||||||
while *TASKS_RUNNING.lock() > 1 {
|
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
|
||||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*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());
|
path.push(item.name());
|
||||||
let ilias = Arc::clone(&ilias);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async {
|
task::spawn(async {
|
||||||
while *TASKS_RUNNING.lock() > 1 {
|
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
|
||||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*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);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async {
|
task::spawn(async {
|
||||||
while *TASKS_RUNNING.lock() > 1 {
|
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
|
||||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*TASKS_RUNNING.lock() += 1;
|
||||||
@ -563,7 +563,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
|
|||||||
path.push(name);
|
path.push(name);
|
||||||
let ilias = Arc::clone(&ilias);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async {
|
task::spawn(async {
|
||||||
while *TASKS_RUNNING.lock() > 1 {
|
while *TASKS_RUNNING.lock() > ilias.opt.jobs {
|
||||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*TASKS_RUNNING.lock() += 1;
|
||||||
@ -607,7 +607,7 @@ fn process(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl std::future::F
|
|||||||
path.push(name);
|
path.push(name);
|
||||||
let ilias = Arc::clone(&ilias);
|
let ilias = Arc::clone(&ilias);
|
||||||
task::spawn(async move {
|
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;
|
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
*TASKS_RUNNING.lock() += 1;
|
*TASKS_RUNNING.lock() += 1;
|
||||||
@ -651,4 +651,8 @@ struct Opt {
|
|||||||
/// Output directory
|
/// Output directory
|
||||||
#[structopt(short, long, parse(from_os_str))]
|
#[structopt(short, long, parse(from_os_str))]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
|
|
||||||
|
/// Parallel download jobs
|
||||||
|
#[structopt(short, long, default_value = "1")]
|
||||||
|
jobs: usize,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user