@@ -60,7 +60,7 @@ pub fn client(verb: &str, rest: &[String]) -> i32 {
6060 Ok(serde_json::from_str(&line).unwrap_or(Value::Null))
6161 })();
6262 match res {
63- Ok(r) => { println!("{}", r["msg"].as_str().unwrap_or("?")); 0 }
63+ Ok(r) => { println!("{}", r["msg"].as_str().unwrap_or("?")); if r["ok"] == false { 1 } else { 0 } }
6464 Err(e) => { eprintln!("conveyor {verb}: can't reach conveyor at {}: {e}", path.display()); 1 }
6565 }
6666 }
@@ -81,8 +81,9 @@ pub struct Listener {
8181 }
8282
8383 impl Listener {
84- /// Listens on `path` for one ticket; every verb goes to the ticket's timeline.
85- pub fn start(project: &str, id: u32, path: PathBuf) -> std::io::Result<Listener> {
84+ /// Listens on `path` for one ticket; every verb goes to the ticket's timeline. `done` counts
85+ /// only once `check` passes; otherwise the agent gets its message and keeps working.
86+ pub fn start(project: &str, id: u32, path: PathBuf, check: impl Fn() -> Result<(), String> + Send + 'static) -> std::io::Result<Listener> {
8687 let _ = std::fs::remove_file(&path);
8788 let srv = UnixListener::bind(&path)?;
8889 srv.set_nonblocking(true)?;
@@ -91,7 +92,7 @@ impl Listener {
9192 let thread = std::thread::spawn(move || {
9293 while !st.load(Ordering::Relaxed) {
9394 match srv.accept() {
94- Ok((c, _)) => { let _ = handle(&project, id, c, &out); }
95+ Ok((c, _)) => { let _ = handle(&project, id, c, &out, &check); }
9596 Err(_) => std::thread::sleep(Duration::from_millis(100)),
9697 }
9798 }
@@ -107,7 +108,7 @@ impl Listener {
107108 }
108109 }
109110
110-fn handle(project: &str, id: u32, c: UnixStream, outcome: &Mutex<Outcome>) -> std::io::Result<()> {
111+fn handle(project: &str, id: u32, c: UnixStream, outcome: &Mutex<Outcome>, check: &dyn Fn() -> Result<(), String>) -> std::io::Result<()> {
111112 c.set_nonblocking(false)?;
112113 let mut line = String::new();
113114 BufReader::new(&c).read_line(&mut line)?;
@@ -116,7 +117,14 @@ fn handle(project: &str, id: u32, c: UnixStream, outcome: &Mutex<Outcome>) -> st
116117 store::event(project, id, json!({"kind": "verb", "verb": verb, "args": msg["args"]}));
117118 match verb {
118119 "block" => { *outcome.lock().unwrap() = Outcome::Blocked; store::set_state(project, id, "parked"); }
119- "done" => { let mut o = outcome.lock().unwrap(); if *o != Outcome::Blocked { *o = Outcome::Done(msg["args"]["text"].as_str().unwrap_or("").into()); } }
120+ "done" => {
121+ if let Err(e) = check() {
122+ store::event(project, id, json!({"kind": "conveyor", "msg": e}));
123+ return writeln!(&c, "{}", json!({"ok": false, "msg": e}));
124+ }
125+ let mut o = outcome.lock().unwrap();
126+ if *o != Outcome::Blocked { *o = Outcome::Done(msg["args"]["text"].as_str().unwrap_or("").into()); }
127+ }
120128 _ => {}
121129 }
122130 writeln!(&c, "{}", json!({"ok": true, "msg": reply(verb)}))