1use crate::store::Store;
4use serde_json::{json, Value};
5use std::io::Write;
6use time::{format_description::well_known::Rfc3339, OffsetDateTime};
7
8pub fn append(store: &Store, op: &str, tick_id: Option<&str>, verdict: Option<&str>) {
10 let ts = OffsetDateTime::now_utc()
11 .format(&Rfc3339)
12 .unwrap_or_default();
13 let mut e = json!({ "ts": ts, "op": op });
14 if let Some(o) = e.as_object_mut() {
15 if let Some(id) = tick_id {
16 o.insert("tick_id".into(), Value::String(id.into()));
17 }
18 if let Some(v) = verdict {
19 o.insert("verdict".into(), Value::String(v.into()));
20 }
21 }
22 let dir = store.root.join("results");
23 if std::fs::create_dir_all(&dir).is_err() {
24 return;
25 }
26 if let Ok(mut f) = std::fs::OpenOptions::new()
27 .create(true)
28 .append(true)
29 .open(dir.join("events.jsonl"))
30 {
31 let _ = writeln!(f, "{}", serde_json::to_string(&e).unwrap_or_default());
32 }
33}