rinne_types/
blackboard.rs1use std::path::{Path, PathBuf};
9
10use crate::dag::Plan;
11use crate::worker::Usage;
12use crate::Result;
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum NodeStatus {
17 Pending,
19 Running,
21 Succeeded,
23 Failed,
25 Parked,
27}
28
29impl NodeStatus {
30 pub fn as_str(self) -> &'static str {
32 match self {
33 NodeStatus::Pending => "pending",
34 NodeStatus::Running => "running",
35 NodeStatus::Succeeded => "succeeded",
36 NodeStatus::Failed => "failed",
37 NodeStatus::Parked => "parked",
38 }
39 }
40
41 pub fn from_str(s: &str) -> NodeStatus {
43 match s {
44 "running" => NodeStatus::Running,
45 "succeeded" => NodeStatus::Succeeded,
46 "failed" => NodeStatus::Failed,
47 "parked" => NodeStatus::Parked,
48 _ => NodeStatus::Pending,
49 }
50 }
51
52 pub fn label(self) -> &'static str {
53 self.as_str()
54 }
55
56 pub fn is_terminal_success(self) -> bool {
57 matches!(self, NodeStatus::Succeeded)
58 }
59}
60
61pub trait Blackboard {
68 fn workspace(&self) -> &Path;
70 fn progress_path(&self) -> PathBuf;
71 fn save_plan(&self, plan: &Plan) -> Result<()>;
72 fn write_artifact(&self, name: &str, contents: &str) -> Result<()>;
73 fn read_artifact(&self, name: &str) -> Result<String>;
74 fn artifact_exists(&self, name: &str) -> bool;
75 fn write_transcript(&self, node_id: &str, contents: &str) -> Result<()>;
76 fn write_context(&self, node_id: &str, contents: &str) -> Result<()>;
77 fn append_progress(&self, line: &str) -> Result<()>;
78
79 fn ensure_node(&self, node_id: &str) -> Result<()>;
81 fn set_status(&self, node_id: &str, status: NodeStatus) -> Result<()>;
82 fn set_worker(&self, node_id: &str, worker: &str) -> Result<()>;
83 fn status(&self, node_id: &str) -> Result<NodeStatus>;
84 fn incr_iteration(&self, node_id: &str) -> Result<u32>;
85 fn iterations(&self, node_id: &str) -> Result<u32>;
86 fn record_usage(&self, node_id: &str, worker: &str, usage: &Usage) -> Result<()>;
87 fn total_iterations(&self) -> Result<u32>;
88 fn total_usage(&self) -> Result<Usage>;
89 fn set_meta(&self, key: &str, value: &str) -> Result<()>;
90 fn meta(&self, key: &str) -> Result<Option<String>>;
91}