Skip to content
Myr

job.rs

This file

Path

src/exec/job.rs

67 lines · 2.1 KiB · Rust

Last changed by

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

History of this file

Take it

The walk stopped after 200 commits: lines older than 17d849d point at it.

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

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

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 2–13why, one step back
2
3use crate::config::Config;4use crate::error::print_error;5use crate::exit_codes::{merge_exitcodes, ExitCode};6use crate::walk::WorkerResult;78use super::CommandSet;910/// An event loop that listens for inputs from the `rx` receiver. Each received input will11/// generate a command with the supplied command template. The generated command will then12/// be executed, and this process will continue until the receiver's sender has closed.13pub fn job(

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

line 14why, one step back
14 results: impl IntoIterator<Item = WorkerResult>,

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

lines 15–16why, one step back
15 cmd: &CommandSet,
16 out_perm: &Mutex<()>,

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 17–21why, one step back
17 config: &Config,
18) -> ExitCode {19 // Output should be buffered when only running a single thread20 let buffer_output: bool = config.threads > 1;21

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

lines 22–23why, one step back
22 let mut ret = ExitCode::Success;
23 for result in results {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 24–25why, one step back
24 // Obtain the next result from the receiver, else if the channel
25 // has closed, exit from the loop

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

lines 26–28why, one step back
26 let dir_entry = match result {
27 WorkerResult::Entry(dir_entry) => dir_entry,28 WorkerResult::Error(err) => {

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 29–36why, one step back
29 if config.show_filesystem_errors {
30 print_error(err.to_string());31 }32 continue;33 }34 };3536 // Generate a command, execute it and store its exit code.

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

line 37why, one step back
37 let code = cmd.execute(

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 38why, one step back
38 dir_entry.stripped_path(config),

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 39why, one step back
39 config.path_separator.as_deref(),

Merge pull request #1283 from tmccombs/new-rust-versionTavian Barnesbefore adoptione4bca10

line 40why, one step back
40 out_perm,

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 41why, one step back
41 buffer_output,

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

lines 42–43why, one step back
42 );
43 ret = merge_exitcodes([ret, code]);

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 44–45why, one step back
44 }
45 // Returns error in case of any error.

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

line 46why, one step back
46 ret

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 47–48why, one step back
47}
48

Merge pull request #1422 from tavianator/batchTavian Barnesbefore adoption84f032e

lines 49–54why, one step back
49pub fn batch(
50 results: impl IntoIterator<Item = WorkerResult>,51 cmd: &CommandSet,52 config: &Config,53) -> ExitCode {54 let paths = results

Compute colors in parallelTavian Barnesbefore adoption17d849d

lines 55–65why, one step back
55 .into_iter()
56 .filter_map(|worker_result| match worker_result {57 WorkerResult::Entry(dir_entry) => Some(dir_entry.into_stripped_path(config)),58 WorkerResult::Error(err) => {59 if config.show_filesystem_errors {60 print_error(err.to_string());61 }62 None63 }64 });65

Merge pull request #1067 from tmccombs/clap-deriveDavid Peterbefore adoption13a47c3

line 66why, one step back
66 cmd.execute_batch(paths, config.batch_size, config.path_separator.as_deref())

Compute colors in parallelTavian Barnesbefore adoption17d849d

line 67why, one step back
67}