Skip to content

Commit

Permalink
Printing errors from worker jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbor committed Jul 19, 2024
1 parent 3bdfc48 commit 5ae0e62
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/cproj/zinn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
echo "compiling."
sleep 1
echo "compiling.."
false
sleep 1
echo "compiling..."
sleep 1
Expand Down
14 changes: 10 additions & 4 deletions src/barkeeper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{queue::JobState, JobRealization};
use crate::{queue::JobState, JobRealization, ZinnError};


pub trait StateTracker {
Expand All @@ -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<ZinnError>);
fn start(&self);
fn set_prefix(&mut self, prefix: String);
fn clear_status(&mut self);
Expand Down Expand Up @@ -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<ZinnError>) {
println!("{}", job_finished_msg(job, state));
if let Some(e) = error {
println!("{}", e);
}
}

fn start(&self) {}
Expand Down Expand Up @@ -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<ZinnError>) {
self.bar.println(job_finished_msg(job, state));
if let Some(e) = error {
self.bar.println(e.to_string());
}
self.main_bar.inc(1)
}

Expand Down
1 change: 0 additions & 1 deletion src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5ae0e62

Please sign in to comment.