diff --git a/lib/crates/fabro-workflow/src/lib.rs b/lib/crates/fabro-workflow/src/lib.rs index 53d91c91e..ad78f076d 100644 --- a/lib/crates/fabro-workflow/src/lib.rs +++ b/lib/crates/fabro-workflow/src/lib.rs @@ -29,18 +29,6 @@ pub(crate) fn millis_u64(d: std::time::Duration) -> u64 { u64::try_from(d.as_millis()).unwrap_or(u64::MAX) } -/// Save a value as pretty-printed JSON to a file. -pub(crate) fn save_json( - value: &T, - path: &std::path::Path, - label: &str, -) -> error::Result<()> { - let json = serde_json::to_string_pretty(value) - .map_err(|e| error::FabroError::Checkpoint(format!("{label} serialize failed: {e}")))?; - std::fs::write(path, json)?; - Ok(()) -} - /// Load a value from a JSON file. pub(crate) fn load_json( path: &std::path::Path, diff --git a/lib/crates/fabro-workflow/src/records/checkpoint.rs b/lib/crates/fabro-workflow/src/records/checkpoint.rs index a79781ba5..82aab0044 100644 --- a/lib/crates/fabro-workflow/src/records/checkpoint.rs +++ b/lib/crates/fabro-workflow/src/records/checkpoint.rs @@ -22,7 +22,6 @@ pub trait CheckpointExt { ) -> Self where Self: Sized; - fn save(&self, path: &Path) -> CrateResult<()>; fn load(path: &Path) -> CrateResult where Self: Sized; @@ -55,11 +54,6 @@ impl CheckpointExt for Checkpoint { } } - fn save(&self, path: &Path) -> CrateResult<()> { - tracing::debug!(path = %path.display(), node = %self.current_node, "Saving checkpoint"); - crate::save_json(self, path, "checkpoint") - } - fn load(path: &Path) -> CrateResult { tracing::debug!(path = %path.display(), "Loading checkpoint"); crate::load_json(path, "checkpoint") diff --git a/lib/crates/fabro-workflow/src/records/conclusion.rs b/lib/crates/fabro-workflow/src/records/conclusion.rs index 705c750be..6b98dcf0f 100644 --- a/lib/crates/fabro-workflow/src/records/conclusion.rs +++ b/lib/crates/fabro-workflow/src/records/conclusion.rs @@ -1,22 +1 @@ -use std::path::Path; - pub use fabro_types::conclusion::{Conclusion, StageSummary}; - -use crate::error::Result as CrateResult; - -pub trait ConclusionExt { - fn save(&self, path: &Path) -> CrateResult<()>; - fn load(path: &Path) -> CrateResult - where - Self: Sized; -} - -impl ConclusionExt for Conclusion { - fn save(&self, path: &Path) -> CrateResult<()> { - crate::save_json(self, path, "conclusion") - } - - fn load(path: &Path) -> CrateResult { - crate::load_json(path, "conclusion") - } -} diff --git a/lib/crates/fabro-workflow/src/records/mod.rs b/lib/crates/fabro-workflow/src/records/mod.rs index f1c1938de..48a94b1db 100644 --- a/lib/crates/fabro-workflow/src/records/mod.rs +++ b/lib/crates/fabro-workflow/src/records/mod.rs @@ -4,6 +4,6 @@ mod run; mod start; pub use checkpoint::{Checkpoint, CheckpointExt}; -pub use conclusion::{Conclusion, ConclusionExt, StageSummary}; +pub use conclusion::{Conclusion, StageSummary}; pub use run::{RunRecord, RunRecordExt}; pub use start::{StartRecord, StartRecordExt}; diff --git a/lib/crates/fabro-workflow/src/records/run.rs b/lib/crates/fabro-workflow/src/records/run.rs index 849fd7aa5..56c3797a7 100644 --- a/lib/crates/fabro-workflow/src/records/run.rs +++ b/lib/crates/fabro-workflow/src/records/run.rs @@ -10,7 +10,6 @@ pub trait RunRecordExt { fn file_name() -> &'static str where Self: Sized; - fn save(&self, run_dir: &Path) -> CrateResult<()>; fn load(run_dir: &Path) -> CrateResult where Self: Sized; @@ -25,10 +24,6 @@ impl RunRecordExt for RunRecord { FILE_NAME } - fn save(&self, run_dir: &Path) -> CrateResult<()> { - crate::save_json(self, &run_dir.join(FILE_NAME), "run record") - } - fn load(run_dir: &Path) -> CrateResult { crate::load_json(&run_dir.join(FILE_NAME), "run record") } diff --git a/lib/crates/fabro-workflow/src/records/start.rs b/lib/crates/fabro-workflow/src/records/start.rs index f27aabcb4..42fbf7d42 100644 --- a/lib/crates/fabro-workflow/src/records/start.rs +++ b/lib/crates/fabro-workflow/src/records/start.rs @@ -10,7 +10,6 @@ pub trait StartRecordExt { fn file_name() -> &'static str where Self: Sized; - fn save(&self, run_dir: &Path) -> CrateResult<()>; fn load(run_dir: &Path) -> CrateResult where Self: Sized; @@ -21,10 +20,6 @@ impl StartRecordExt for StartRecord { FILE_NAME } - fn save(&self, run_dir: &Path) -> CrateResult<()> { - crate::save_json(self, &run_dir.join(FILE_NAME), "start record") - } - fn load(run_dir: &Path) -> CrateResult { crate::load_json(&run_dir.join(FILE_NAME), "start record") } diff --git a/lib/crates/fabro-workflow/src/run_status.rs b/lib/crates/fabro-workflow/src/run_status.rs index b82f0c52a..2fc034825 100644 --- a/lib/crates/fabro-workflow/src/run_status.rs +++ b/lib/crates/fabro-workflow/src/run_status.rs @@ -5,26 +5,15 @@ pub use fabro_types::status::{ }; pub trait RunStatusRecordExt { - fn save(&self, path: &Path) -> std::io::Result<()>; fn load(path: &Path) -> std::io::Result where Self: Sized; } impl RunStatusRecordExt for RunStatusRecord { - fn save(&self, path: &Path) -> std::io::Result<()> { - let json = serde_json::to_string_pretty(self).map_err(std::io::Error::other)?; - std::fs::write(path, json) - } - fn load(path: &Path) -> std::io::Result { let data = std::fs::read_to_string(path)?; serde_json::from_str(&data) .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e)) } } - -pub fn write_run_status(run_dir: &Path, status: RunStatus, reason: Option) { - let record = RunStatusRecord::new(status, reason); - let _ = record.save(&run_dir.join("status.json")); -} diff --git a/lib/crates/fabro-workflow/src/test_support.rs b/lib/crates/fabro-workflow/src/test_support.rs index 7220d0b29..d8bba6de9 100644 --- a/lib/crates/fabro-workflow/src/test_support.rs +++ b/lib/crates/fabro-workflow/src/test_support.rs @@ -16,7 +16,7 @@ use crate::handler::HandlerRegistry; use crate::outcome::Outcome; use crate::pipeline; use crate::pipeline::types::Initialized; -use crate::records::{Checkpoint, CheckpointExt}; +use crate::records::Checkpoint; use crate::run_options::RunOptions; struct InitializedOptions { @@ -192,7 +192,9 @@ async fn persist_run_artifacts_for_tests(run_store: &SlateRunStore, run_dir: &st }; if let Some(checkpoint) = state.checkpoint.as_ref() { - let _ = checkpoint.save(&run_dir.join("checkpoint.json")); + if let Ok(json) = serde_json::to_string_pretty(checkpoint) { + let _ = std::fs::write(run_dir.join("checkpoint.json"), json); + } } if let Some(final_patch) = state.final_patch.as_ref() {