rinne_types/
blackboard.rs1use std::path::{Path, PathBuf};
9
10use crate::dag::Plan;
11use crate::graph::CodeGraph;
12use crate::worker::Usage;
13use crate::Result;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum NodeStatus {
18 Pending,
20 Running,
22 Succeeded,
24 Failed,
26 Parked,
28}
29
30impl NodeStatus {
31 pub fn as_str(self) -> &'static str {
33 match self {
34 NodeStatus::Pending => "pending",
35 NodeStatus::Running => "running",
36 NodeStatus::Succeeded => "succeeded",
37 NodeStatus::Failed => "failed",
38 NodeStatus::Parked => "parked",
39 }
40 }
41
42 pub fn parse_label(s: &str) -> NodeStatus {
46 match s {
47 "running" => NodeStatus::Running,
48 "succeeded" => NodeStatus::Succeeded,
49 "failed" => NodeStatus::Failed,
50 "parked" => NodeStatus::Parked,
51 _ => NodeStatus::Pending,
52 }
53 }
54
55 #[allow(clippy::should_implement_trait)]
57 pub fn from_str(s: &str) -> NodeStatus {
58 Self::parse_label(s)
59 }
60
61 pub fn label(self) -> &'static str {
62 self.as_str()
63 }
64
65 pub fn is_terminal_success(self) -> bool {
66 matches!(self, NodeStatus::Succeeded)
67 }
68}
69
70pub trait Blackboard {
77 fn workspace(&self) -> &Path;
79 fn progress_path(&self) -> PathBuf;
80 fn save_plan(&self, plan: &Plan) -> Result<()>;
81 fn write_artifact(&self, name: &str, contents: &str) -> Result<()>;
82 fn read_artifact(&self, name: &str) -> Result<String>;
83 fn artifact_exists(&self, name: &str) -> bool;
84 fn write_transcript(&self, node_id: &str, contents: &str) -> Result<()>;
85 fn write_context(&self, node_id: &str, contents: &str) -> Result<()>;
86 fn append_progress(&self, line: &str) -> Result<()>;
87
88 fn ensure_node(&self, node_id: &str) -> Result<()>;
90 fn set_status(&self, node_id: &str, status: NodeStatus) -> Result<()>;
91 fn set_worker(&self, node_id: &str, worker: &str) -> Result<()>;
92 fn status(&self, node_id: &str) -> Result<NodeStatus>;
93 fn incr_iteration(&self, node_id: &str) -> Result<u32>;
94 fn iterations(&self, node_id: &str) -> Result<u32>;
95 fn record_usage(&self, node_id: &str, worker: &str, usage: &Usage) -> Result<()>;
96 fn total_iterations(&self) -> Result<u32>;
97 fn total_usage(&self) -> Result<Usage>;
98 fn set_meta(&self, key: &str, value: &str) -> Result<()>;
99 fn meta(&self, key: &str) -> Result<Option<String>>;
100
101 fn code_graph(&self) -> Option<&dyn CodeGraph> {
106 None
107 }
108
109 fn reindex_file(&self, _abs: &Path) {}
112}