horde_sdk.worker.chaining.flow¶
Chain flow construction and validation.
A ChainFlow is the immutable routing plan for a unit of work: which stages exist, what they require, and how
they connect. Build one with ChainFlowBuilder; the build step validates the topology once so consumers can rely
on the flow's shape without re-checking.
ChainFlowValidationError ¶
ChainFlow ¶
An immutable, validated directed acyclic graph of stage nodes.
Instances are created by ChainFlowBuilder.build; the constructor assumes already-validated inputs.
Source code in horde_sdk/worker/chaining/flow.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
source_handle
property
¶
The handle of the flow's single starting node.
__init__ ¶
__init__(
*,
graph: TypedChainGraph[ChainNodeHandle],
nodes: dict[ChainNodeHandle, ChainStageNode],
edges: dict[
tuple[ChainNodeHandle, ChainNodeHandle], ChainEdge
]
) -> None
Initialize the flow from builder-validated parts.
Parameters:
-
graph(TypedChainGraph[ChainNodeHandle]) –The validated topology.
-
nodes(dict[ChainNodeHandle, ChainStageNode]) –The node payloads keyed by handle.
-
edges(dict[tuple[ChainNodeHandle, ChainNodeHandle], ChainEdge]) –The edge payloads keyed by (source, target).
Source code in horde_sdk/worker/chaining/flow.py
get_node ¶
Return the stage node for a handle.
Parameters:
-
handle(ChainNodeHandle) –The handle to resolve.
Raises:
-
KeyError–If the handle is not part of this flow.
Source code in horde_sdk/worker/chaining/flow.py
get_node_handle ¶
Return the handle for a node name.
Parameters:
-
name(str) –The node name.
Raises:
-
KeyError–If no node has the given name.
Source code in horde_sdk/worker/chaining/flow.py
get_edge ¶
Return the edge between two handles.
Parameters:
-
source(ChainNodeHandle) –The edge origin.
-
target(ChainNodeHandle) –The edge destination.
Raises:
-
KeyError–If there is no such edge.
Source code in horde_sdk/worker/chaining/flow.py
successors ¶
predecessors ¶
descendants ¶
Return all nodes reachable from a node, excluding the node itself.
node_for_entry_progress ¶
Return the node whose stage begins at the given generation progress, if any.
node_for_completion_progress ¶
Return the node whose stage completes at the given generation progress, if any.
ChainFlowBuilder ¶
Accumulates stage nodes and edges, then validates and freezes them into a ChainFlow.
Source code in horde_sdk/worker/chaining/flow.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
__init__ ¶
Initialize an empty builder.
Source code in horde_sdk/worker/chaining/flow.py
add_stage ¶
Add a stage node to the flow under construction.
Parameters:
-
node(ChainStageNode) –The stage to add.
Returns:
-
ChainNodeHandle(ChainNodeHandle) –The handle referring to the added node.
Raises:
-
ChainFlowValidationError–If a node with the same name already exists.
Source code in horde_sdk/worker/chaining/flow.py
connect ¶
connect(
source: ChainNodeHandle,
target: ChainNodeHandle,
kind: CHAIN_EDGE_KIND = CHAIN_EDGE_KIND.SAME_GENERATION,
*,
edge: ChainEdge | None = None
) -> ChainEdge
Connect two stages with a directed edge.
Parameters:
-
source(ChainNodeHandle) –The stage whose completion feeds the edge.
-
target(ChainNodeHandle) –The stage that becomes eligible when the edge fires.
-
kind(CHAIN_EDGE_KIND, default:SAME_GENERATION) –The edge kind for a default edge. Defaults to CHAIN_EDGE_KIND.SAME_GENERATION.
-
edge(ChainEdge | None, default:None) –A pre-built edge to use instead of constructing a default one. Its source and target must match the given handles. Defaults to None.
Returns:
-
ChainEdge(ChainEdge) –The edge that was added.
Raises:
-
ChainFlowValidationError–If either handle is unknown or the edge endpoints do not match.
Source code in horde_sdk/worker/chaining/flow.py
build ¶
Validate the accumulated topology and freeze it into a ChainFlow.
Returns:
-
ChainFlow(ChainFlow) –The validated flow.
Raises:
-
ChainFlowValidationError–If the flow is empty, cyclic, disconnected, has multiple starting nodes, or two stages share an entry or completion progress state.