Skip to content

Commit

Permalink
better to report by batch
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed May 7, 2024
1 parent f4a038f commit e5159c0
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/directsketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ pub async fn download_and_sketch(
let mut accessions = accession_info.into_iter().peekable();

let mut futures = Vec::new();
let mut dispatched_count = 0;
dispatched_count += 1;
let mut n_processed = 0;

while accessions.peek().is_some() {
// Wait for the next interval to allow starting new tasks
Expand Down Expand Up @@ -460,24 +459,23 @@ pub async fn download_and_sketch(
.await
});
futures.push(fut);
if dispatched_count % reporting_threshold == 0 {
let percent_processed =
((dispatched_count as f64 / n_accs as f64) * 100.0).round();
println!(
"Starting accession {}/{} ({}%)",
dispatched_count, n_accs, percent_processed
);
}
} else {
break; // If no more accessions, break out of the loop
}
}

// Check if enough tasks have been collected for a batch
if futures.len() >= batch_size {
// report n_processed
n_processed += futures.len();
let percent_processed = ((n_processed as f64 / n_accs as f64) * 100.0).round();
println!(
"Sketched accession {}/{} ({}%)",
n_processed, n_accs, percent_processed
);
let results = futures::future::join_all(futures.drain(..batch_size)).await;
for result in results {
match result.expect("Task panicked") {
match result.expect("download panicked") {
Ok((processed_sigs, failed_downloads)) => {
// collect all sigs from the batch
batch_sigs.extend(processed_sigs);
Expand Down

0 comments on commit e5159c0

Please sign in to comment.