job.rs
This file
Path
src/exec/job.rs
77 lines · 2.5 KiB · Rust
Last changed by
Implement `--batch-size` (#866)Devon Hollowoodbefore adoption17dd2a6
History of this fileTake it
The walk stopped after 200 commits: lines older than 1a16003 point at it.
[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 1–18why, one step back1use std::path::PathBuf;2use std::sync::mpsc::Receiver;3use std::sync::{Arc, Mutex};45use crate::error::print_error;6use crate::exit_codes::{merge_exitcodes, ExitCode};7use crate::walk::WorkerResult;89use super::CommandTemplate;1011/// An event loop that listens for inputs from the `rx` receiver. Each received input will12/// generate a command with the supplied command template. The generated command will then13/// be executed, and this process will continue until the receiver's sender has closed.14pub fn job(15 rx: Arc<Mutex<Receiver<WorkerResult>>>,16 cmd: Arc<CommandTemplate>,17 out_perm: Arc<Mutex<()>>,18 show_filesystem_errors: bool,Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060
line 19why, one step back19 buffer_output: bool,[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 20–37why, one step back20) -> ExitCode {21 let mut results: Vec<ExitCode> = Vec::new();22 loop {23 // Create a lock on the shared receiver for this thread.24 let lock = rx.lock().unwrap();2526 // Obtain the next result from the receiver, else if the channel27 // has closed, exit from the loop28 let value: PathBuf = match lock.recv() {29 Ok(WorkerResult::Entry(val)) => val,30 Ok(WorkerResult::Error(err)) => {31 if show_filesystem_errors {32 print_error(err.to_string());33 }34 continue;35 }36 Err(_) => break,37 };Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060
line 38why, one step back38[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 39–41why, one step back39 // Drop the lock so that other threads can read from the receiver.40 drop(lock);41 // Generate a command, execute it and store its exit code.Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060
line 42why, one step back42 results.push(cmd.generate_and_execute(&value, Arc::clone(&out_perm), buffer_output))[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 43–44why, one step back43 }44 // Returns error in case of any error.Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645
line 45why, one step back45 merge_exitcodes(results)[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 46–51why, one step back46}4748pub fn batch(49 rx: Receiver<WorkerResult>,50 cmd: &CommandTemplate,51 show_filesystem_errors: bool,Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060
line 52why, one step back52 buffer_output: bool,Implement `--batch-size` (#866)Devon Hollowoodbefore adoption17dd2a6
line 53why, one step back53 limit: usize,[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
lines 54–63why, one step back54) -> ExitCode {55 let paths = rx.iter().filter_map(|value| match value {56 WorkerResult::Entry(val) => Some(val),57 WorkerResult::Error(err) => {58 if show_filesystem_errors {59 print_error(err.to_string());60 }61 None62 }63 });Implement `--batch-size` (#866)Devon Hollowoodbefore adoption17dd2a6
lines 64–76why, one step back64 if limit == 0 {65 // no limit66 return cmd.generate_and_execute_batch(paths, buffer_output);67 }6869 let mut exit_codes = Vec::new();70 let mut peekable = paths.peekable();71 while peekable.peek().is_some() {72 let limited = peekable.by_ref().take(limit);73 let exit_code = cmd.generate_and_execute_batch(limited, buffer_output);74 exit_codes.push(exit_code);75 }76 merge_exitcodes(exit_codes)[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003
line 77why, one step back77}