use std::path::{Path, PathBuf};
use crate::dag::Plan;
use crate::graph::CodeGraph;
use crate::worker::Usage;
use crate::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeStatus {
Pending,
Running,
Succeeded,
Failed,
Parked,
}
impl NodeStatus {
pub fn as_str(self) -> &'static str {
match self {
NodeStatus::Pending => "pending",
NodeStatus::Running => "running",
NodeStatus::Succeeded => "succeeded",
NodeStatus::Failed => "failed",
NodeStatus::Parked => "parked",
}
}
pub fn parse_label(s: &str) -> NodeStatus {
match s {
"running" => NodeStatus::Running,
"succeeded" => NodeStatus::Succeeded,
"failed" => NodeStatus::Failed,
"parked" => NodeStatus::Parked,
_ => NodeStatus::Pending,
}
}
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> NodeStatus {
Self::parse_label(s)
}
pub fn label(self) -> &'static str {
self.as_str()
}
pub fn is_terminal_success(self) -> bool {
matches!(self, NodeStatus::Succeeded)
}
}
pub trait Blackboard {
fn workspace(&self) -> &Path;
fn progress_path(&self) -> PathBuf;
fn save_plan(&self, plan: &Plan) -> Result<()>;
fn write_artifact(&self, name: &str, contents: &str) -> Result<()>;
fn read_artifact(&self, name: &str) -> Result<String>;
fn artifact_exists(&self, name: &str) -> bool;
fn write_transcript(&self, node_id: &str, contents: &str) -> Result<()>;
fn write_context(&self, node_id: &str, contents: &str) -> Result<()>;
fn append_progress(&self, line: &str) -> Result<()>;
fn ensure_node(&self, node_id: &str) -> Result<()>;
fn set_status(&self, node_id: &str, status: NodeStatus) -> Result<()>;
fn set_worker(&self, node_id: &str, worker: &str) -> Result<()>;
fn status(&self, node_id: &str) -> Result<NodeStatus>;
fn incr_iteration(&self, node_id: &str) -> Result<u32>;
fn iterations(&self, node_id: &str) -> Result<u32>;
fn record_usage(&self, node_id: &str, worker: &str, usage: &Usage) -> Result<()>;
fn total_iterations(&self) -> Result<u32>;
fn total_usage(&self) -> Result<Usage>;
fn set_meta(&self, key: &str, value: &str) -> Result<()>;
fn meta(&self, key: &str) -> Result<Option<String>>;
fn code_graph(&self) -> Option<&dyn CodeGraph> {
None
}
fn reindex_file(&self, _abs: &Path) {}
}