Process CSV mode with persistent worker pool
(args: &Args)
| 16 | |
| 17 | // Process CSV mode with persistent worker pool |
| 18 | pub async fn process_csv_mode(args: &Args) -> Result<(), Error> { |
| 19 | // Parse the CSV file to get all records |
| 20 | let csv_records = match parse_csv_input(args.input_file.as_ref().unwrap()).await { |
| 21 | Ok(records) => records, |
| 22 | Err(e) => return Err(anyhow!("Failed to parse CSV file: {}", e)) |
| 23 | }; |
| 24 | |
| 25 | let total_records = csv_records.len(); |
| 26 | println!("Loaded {} records from CSV file", total_records); |
| 27 | |
| 28 | // Initialize output CSV file |
| 29 | let output_file = "output.csv"; |
| 30 | if let Err(e) = initialize_csv_output(output_file).await { |
| 31 | return Err(anyhow!("Failed to initialize output CSV file: {}", e)); |
| 32 | } |
| 33 | |
| 34 | // Set up channels for worker communication |
| 35 | let (work_tx, work_rx) = async_channel::bounded::<WorkerMessage>(1000); |
| 36 | let (result_tx, result_rx) = async_channel::bounded::<ResultMessage>(1000); |
| 37 | |
| 38 | // Create shared counters |
| 39 | let counters = Arc::new(Counters::new()); |
| 40 | |
| 41 | // Create progress bars |
| 42 | let progress = ProgressBars::new(100); // Initial length will be updated |
| 43 | progress.update_message(&format!("Processing CSV with {} records", total_records)); |
| 44 | |
| 45 | // Create latest hit tracking |
| 46 | let latest_hit = Arc::new(tokio::sync::Mutex::new(None::<String>)); |
| 47 | |
| 48 | // Start the worker pool - these will run for the entire duration |
| 49 | let mut worker_handles = vec![]; |
| 50 | for _ in 0..args.workers { |
| 51 | let worker_work_rx = work_rx.clone(); |
| 52 | let worker_result_tx = result_tx.clone(); |
| 53 | let worker_counters = Arc::clone(&counters); |
| 54 | let worker_subnet = args.subnet.clone(); |
| 55 | let worker_lookup_type = args.lookup_type; |
| 56 | |
| 57 | let handle = tokio::spawn(async move { |
| 58 | csv_worker( |
| 59 | worker_work_rx, |
| 60 | worker_result_tx, |
| 61 | worker_counters, |
| 62 | worker_subnet, |
| 63 | worker_lookup_type, |
| 64 | ).await; |
| 65 | }); |
| 66 | |
| 67 | worker_handles.push(handle); |
| 68 | } |
| 69 | |
| 70 | // Track found records |
| 71 | let mut found_records = 0; |
| 72 | // Track total hits across all records |
| 73 | let mut total_hits = 0; |
| 74 | |
| 75 | for attempt in 0..3 { |
no test coverage detected