Skip to main content

substrate_core/
workflow_port.rs

1//! WorkflowPort — DAG orchestration over dependent tasks.
2//!
3//! Core defines workflow shapes; `substrate-dag` implements graph algorithms
4//! (topological order, ready-set, cycle detection) via petgraph.
5
6use serde::{Deserialize, Serialize};
7
8use crate::error::Result;
9
10/// A node in a workflow DAG.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct WorkflowNode {
13    /// Stable node identifier.
14    pub id: String,
15}
16
17/// A directed dependency edge (`from` must complete before `to` may start).
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub struct WorkflowEdge {
20    /// Upstream task id.
21    pub from: String,
22    /// Downstream task id.
23    pub to: String,
24}
25
26/// A workflow: a DAG of dependent tasks.
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub struct Workflow {
29    /// All task nodes.
30    pub nodes: Vec<WorkflowNode>,
31    /// Dependency edges.
32    pub edges: Vec<WorkflowEdge>,
33}
34
35/// DAG orchestration port.
36pub trait WorkflowPort: Send + Sync {
37    /// Validate the workflow is acyclic; reject cycles.
38    fn validate_acyclic(&self, workflow: &Workflow) -> Result<()>;
39
40    /// Return a topological execution order (dependencies first).
41    fn topological_order(&self, workflow: &Workflow) -> Result<Vec<String>>;
42
43    /// Return node ids whose dependencies are all in `completed` and not yet done.
44    fn ready_set(&self, workflow: &Workflow, completed: &[String]) -> Result<Vec<String>>;
45}