Skip to main content

devsper_scheduler/
lib.rs

1use devsper_core::{GraphSnapshot, NodeId};
2use devsper_graph::GraphHandle;
3
4/// Wraps GraphHandle with a scheduler-oriented API.
5/// All state lives in the GraphActor; this is a coordination facade.
6pub struct Scheduler {
7    handle: GraphHandle,
8}
9
10impl Scheduler {
11    pub fn new(handle: GraphHandle) -> Self {
12        Self { handle }
13    }
14
15    /// Returns currently runnable node IDs.
16    pub async fn get_ready(&self) -> Vec<NodeId> {
17        self.handle.get_ready().await
18    }
19
20    /// Claim a node for execution. Returns true if this caller won the race.
21    pub async fn claim(&self, id: NodeId) -> bool {
22        self.handle.claim(id).await
23    }
24
25    /// Mark a node completed with its result.
26    pub async fn complete(&self, id: NodeId, result: serde_json::Value) {
27        self.handle.complete(id, result).await;
28    }
29
30    /// Mark a node failed.
31    pub async fn fail(&self, id: NodeId, error: String) {
32        self.handle.fail(id, error).await;
33    }
34
35    /// Get a snapshot of current graph state.
36    pub async fn snapshot(&self) -> Option<GraphSnapshot> {
37        self.handle.snapshot().await
38    }
39
40    /// Access the underlying GraphHandle (for mutations).
41    pub fn handle(&self) -> &GraphHandle {
42        &self.handle
43    }
44}