pub struct WorkflowDag {
pub name: String,
pub nodes: BTreeMap<String, DagNode>,
pub levels: Vec<Vec<String>>,
pub roots: Vec<String>,
pub leaves: Vec<String>,
}Expand description
The workflow DAG — compiled from WorkflowConfig.
Contains the full dependency graph and supports:
- Topological ordering
- Parallel level grouping
- Dependency queries
- Root/leaf detection
Fields§
§name: StringThe workflow name.
nodes: BTreeMap<String, DagNode>All nodes in the DAG, keyed by step ID.
BTreeMap (not HashMap) is intentional: it makes iteration order
deterministic across runs, so roots/leaves/levels are stable —
important for reproducible workflow compilation and snapshot tests.
levels: Vec<Vec<String>>The execution levels (parallel groups). Level 0 contains root nodes (no dependencies), Level 1 contains nodes that depend only on Level 0, etc.
roots: Vec<String>Root node IDs (no dependencies).
leaves: Vec<String>Leaf node IDs (no children).
Implementations§
Source§impl WorkflowDag
impl WorkflowDag
Sourcepub fn build(&mut self)
pub fn build(&mut self)
Build the dependency edges and compute levels.
After all nodes are added, call this to:
- Resolve
depends_on→ setchildrenon parent nodes - Compute parallel levels via BFS
- Identify root and leaf nodes
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes.
Sourcepub fn level_count(&self) -> usize
pub fn level_count(&self) -> usize
Get the number of levels (parallel groups).
Sourcepub fn level_nodes(&self, level: usize) -> Vec<&DagNode>
pub fn level_nodes(&self, level: usize) -> Vec<&DagNode>
Get nodes at a specific level.
Sourcepub fn topological_order(&self) -> Vec<String>
pub fn topological_order(&self) -> Vec<String>
Get all node IDs in topological order (level 0 → level N).
Sourcepub fn has_cycle(&self) -> bool
pub fn has_cycle(&self) -> bool
Check if the DAG has any cycles.
Uses Kahn’s algorithm — if after removing all nodes with no dependencies, some nodes remain, there’s a cycle.
Sourcepub fn transitive_deps(&self, node_id: &str) -> HashSet<String>
pub fn transitive_deps(&self, node_id: &str) -> HashSet<String>
Get all dependencies (transitive) of a node.