use super::Pipeline;
use super::types::PipelineError;
use std::thread;
use std::time::Duration;
type ReadJoinHandle =
thread::JoinHandle<Result<(usize, usize, Duration, Duration, Duration), PipelineError>>;
type ParseJoinHandle = thread::JoinHandle<(usize, usize, usize, Duration, Duration, Duration)>;
impl Pipeline {
pub(super) fn join_read_workers(
&self,
handles: Vec<ReadJoinHandle>,
) -> (usize, usize, Duration, Duration, Duration) {
let mut files = 0;
let mut errors = 0;
let mut input_wait = Duration::ZERO;
let mut output_wait = Duration::ZERO;
let mut max_wall_time = Duration::ZERO;
for handle in handles {
match handle.join() {
Ok(Ok((f, e, i, o, w))) => {
files += f;
errors += e;
input_wait += i;
output_wait += o;
if w > max_wall_time {
max_wall_time = w;
}
}
Ok(Err(e)) => {
tracing::error!(target: "pipeline", "READ worker error: {e}");
errors += 1;
}
Err(_) => {
tracing::error!(target: "pipeline", "READ worker panicked");
errors += 1;
}
}
}
(files, errors, input_wait, output_wait, max_wall_time)
}
pub(super) fn join_parse_workers(
&self,
handles: Vec<ParseJoinHandle>,
) -> (usize, usize, usize, Duration, Duration, Duration) {
let mut files = 0;
let mut errors = 0;
let mut symbols = 0;
let mut input_wait = Duration::ZERO;
let mut output_wait = Duration::ZERO;
let mut max_wall_time = Duration::ZERO;
for handle in handles {
match handle.join() {
Ok((f, e, s, i, o, w)) => {
files += f;
errors += e;
symbols += s;
input_wait += i;
output_wait += o;
if w > max_wall_time {
max_wall_time = w;
}
}
Err(_) => {
tracing::error!(target: "pipeline", "PARSE worker panicked");
errors += 1;
}
}
}
(
files,
errors,
symbols,
input_wait,
output_wait,
max_wall_time,
)
}
}