Skip to content
Myr

job.rs

This file

Path

src/exec/job.rs

78 lines · 2.5 KiB · Rust

Last changed by

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

History of this file

Take 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

line 1why, one step back
1use std::sync::{Arc, Mutex};

Merge pull request #895 from tavianator/receiver-bufferTavian Barnesbefore adoption7fe4bfa

lines 2–3why, one step back
2
3use crossbeam_channel::Receiver;

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

line 4why, one step back
4

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

line 5why, one step back
5use crate::entry::DirEntry;

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 6–19why, one step back
6use crate::error::print_error;
7use crate::exit_codes::{merge_exitcodes, ExitCode};8use crate::walk::WorkerResult;910use super::CommandTemplate;1112/// An event loop that listens for inputs from the `rx` receiver. Each received input will13/// generate a command with the supplied command template. The generated command will then14/// be executed, and this process will continue until the receiver's sender has closed.15pub fn job(16 rx: Arc<Mutex<Receiver<WorkerResult>>>,17 cmd: Arc<CommandTemplate>,18 out_perm: Arc<Mutex<()>>,19 show_filesystem_errors: bool,

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

line 20why, one step back
20 buffer_output: bool,

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 21–28why, one step back
21) -> ExitCode {
22 let mut results: Vec<ExitCode> = Vec::new();23 loop {24 // Create a lock on the shared receiver for this thread.25 let lock = rx.lock().unwrap();2627 // Obtain the next result from the receiver, else if the channel28 // has closed, exit from the loop

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

lines 29–30why, one step back
29 let value: DirEntry = match lock.recv() {
30 Ok(WorkerResult::Entry(val)) => val,

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 31–38why, one step back
31 Ok(WorkerResult::Error(err)) => {
32 if show_filesystem_errors {33 print_error(err.to_string());34 }35 continue;36 }37 Err(_) => break,38 };

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

line 39why, one step back
39

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 40–42why, one step back
40 // Drop the lock so that other threads can read from the receiver.
41 drop(lock);42 // Generate a command, execute it and store its exit code.

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

line 43why, one step back
43 results.push(cmd.generate_and_execute(value.path(), 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 44–45why, one step back
44 }
45 // Returns error in case of any error.

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 46why, one step back
46 merge_exitcodes(results)

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 47–52why, one step back
47}
4849pub fn batch(50 rx: Receiver<WorkerResult>,51 cmd: &CommandTemplate,52 show_filesystem_errors: bool,

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

line 53why, one step back
53 buffer_output: bool,

Implement `--batch-size` (#866)Devon Hollowoodbefore adoption17dd2a6

line 54why, one step back
54 limit: usize,

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 55–56why, one step back
55) -> ExitCode {
56 let paths = rx.iter().filter_map(|value| match value {

send DirEntries to output instead of just pathJonathan Gorenbefore adoption813a802

line 57why, one step back
57 WorkerResult::Entry(val) => Some(val.path().to_owned()),

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

lines 58–64why, one step back
58 WorkerResult::Error(err) => {
59 if show_filesystem_errors {60 print_error(err.to_string());61 }62 None63 }64 });

Implement `--batch-size` (#866)Devon Hollowoodbefore adoption17dd2a6

lines 65–77why, one step back
65 if limit == 0 {
66 // no limit67 return cmd.generate_and_execute_batch(paths, buffer_output);68 }6970 let mut exit_codes = Vec::new();71 let mut peekable = paths.peekable();72 while peekable.peek().is_some() {73 let limited = peekable.by_ref().take(limit);74 let exit_code = cmd.generate_and_execute_batch(limited, buffer_output);75 exit_codes.push(exit_code);76 }77 merge_exitcodes(exit_codes)

[ownership][errs] ':' and '' args to --owner result in noop; reject strings with more than one ':'Alexandru Macoveibefore adoption1a16003

line 78why, one step back
78}