diff --git a/examples/cproj/zinn.yaml b/examples/cproj/zinn.yaml index e513139..6dddbba 100644 --- a/examples/cproj/zinn.yaml +++ b/examples/cproj/zinn.yaml @@ -20,6 +20,7 @@ jobs: echo "compiling." sleep 1 echo "compiling.." + false sleep 1 echo "compiling..." sleep 1 diff --git a/src/barkeeper.rs b/src/barkeeper.rs index 695a64e..f1ff5c7 100644 --- a/src/barkeeper.rs +++ b/src/barkeeper.rs @@ -1,4 +1,4 @@ -use crate::{queue::JobState, JobRealization}; +use crate::{queue::JobState, JobRealization, ZinnError}; pub trait StateTracker { @@ -9,7 +9,7 @@ pub trait StateTracker { } pub trait ThreadStateTracker: Send { - fn job_completed(&self, job: JobRealization, state: JobState); + fn job_completed(&self, job: JobRealization, state: JobState, error: Option); fn start(&self); fn set_prefix(&mut self, prefix: String); fn clear_status(&mut self); @@ -99,8 +99,11 @@ impl StateTracker for DummyBarkeeper { } impl ThreadStateTracker for DummyThreadBarkeeper { - fn job_completed(&self, job: JobRealization, state: JobState) { + fn job_completed(&self, job: JobRealization, state: JobState, error: Option) { println!("{}", job_finished_msg(job, state)); + if let Some(e) = error { + println!("{}", e); + } } fn start(&self) {} @@ -128,8 +131,11 @@ impl ThreadStateTracker for ThreadBarkeeper { self.bar.enable_steady_tick(std::time::Duration::from_millis(75)); } - fn job_completed(&self, job: JobRealization, state: JobState) { + fn job_completed(&self, job: JobRealization, state: JobState, error: Option) { self.bar.println(job_finished_msg(job, state)); + if let Some(e) = error { + self.bar.println(e.to_string()); + } self.main_bar.inc(1) } diff --git a/src/job.rs b/src/job.rs index 7dbc64b..718ee2c 100644 --- a/src/job.rs +++ b/src/job.rs @@ -7,7 +7,6 @@ use std::io::{BufRead, BufReader}; use std::sync::Arc; use handlebars::Handlebars; -use handlebars::Renderable; use serde::{Deserialize, Serialize}; use crate::barkeeper::ThreadStateTracker; diff --git a/src/main.rs b/src/main.rs index 632a1ca..fcb4008 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,7 +155,7 @@ enum TemplateType { impl TemplateType { - fn to_name(&self, suffix: &[&str; 3]) -> String { + fn to_name(self, suffix: &[&str; 3]) -> String { use TemplateType::*; // prefixes must not be the same or similar match self { diff --git a/src/worker.rs b/src/worker.rs index 9c5e610..fec76bd 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -9,10 +9,12 @@ pub fn run_worker(queue: Queue, mut tracker: impl ThreadStateTracker, options: O if let Some(job) = queue.fetch() { tracker.set_prefix(job.to_string()); - let state = job.run(&mut tracker, &options) - .map_err(|e| { eprintln!("{}", e); e }) // TODO: Better error messages - .unwrap_or(JobState::Failed); - tracker.job_completed(job.clone(), state); + let result = job.run(&mut tracker, &options); + let state = match &result { + Ok(state) => *state, + Err(_) => JobState::Failed, + }; + tracker.job_completed(job.clone(), state, result.err()); queue.finished(job, state); } else { break;