pub struct NodeContext {
pub state: State,
pub config: ExecutionConfig,
pub step: usize,
/* private fields */
}Expand description
Context passed to nodes during execution
Fields§
§state: StateCurrent graph state (read-only view)
config: ExecutionConfigConfiguration for this execution
step: usizeCurrent step number
Implementations§
Source§impl NodeContext
impl NodeContext
Sourcepub fn new(state: State, config: ExecutionConfig, step: usize) -> Self
pub fn new(state: State, config: ExecutionConfig, step: usize) -> Self
Create a new node context
Sourcepub fn parent_schema(&self) -> Option<Arc<StateSchema>>
pub fn parent_schema(&self) -> Option<Arc<StateSchema>>
The machinery for invoking other nodes, if this context has it. The schema of the graph running this node.
Attached by the executor. A node that projects state between two schemas needs it; most nodes do not.
Sourcepub fn set_parent_schema(&mut self, schema: Arc<StateSchema>)
pub fn set_parent_schema(&mut self, schema: Arc<StateSchema>)
Attaches the running graph’s schema.
Sourcepub async fn run_node(&self, child: &str, input: Value) -> Result<Value>
pub async fn run_node(&self, child: &str, input: Value) -> Result<Value>
Invoke another node and await its output.
The child sees this node’s state with input merged over it, and returns
its updates as one object. Nothing is applied to the graph’s state: the
caller decides what to do with the result.
A child that already completed under the same identity is not run again
after a resume. See crate::child for how that identity is formed, and
why a resumable parent should pass its own run id.
§Errors
Returns GraphError::NodeNotFound
when no node has that name, whatever the child returns, and
GraphError::Interrupted when the
child pauses.
Sourcepub async fn run_node_with(
&self,
child: &str,
input: Value,
options: RunNodeOptions,
) -> Result<Value>
pub async fn run_node_with( &self, child: &str, input: Value, options: RunNodeOptions, ) -> Result<Value>
Sourcepub fn get_as<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get_as<T: DeserializeOwned>(&self, key: &str) -> Option<T>
Get a value from state as a specific type
Sourcepub fn report_progress(&self)
pub fn report_progress(&self)
Report progress, resetting the idle timeout counter.
Nodes performing long-running work should call this periodically to prevent the idle timeout from firing. If no progress handle is attached (e.g., when no idle timeout is configured), this is a no-op.
§Example
async fn execute(&self, ctx: &NodeContext) -> Result<NodeOutput> {
for chunk in large_dataset.chunks(100) {
process(chunk).await;
ctx.report_progress(); // reset idle timeout
}
Ok(NodeOutput::new())
}Sourcepub fn set_progress_handle(&mut self, handle: ProgressHandle)
pub fn set_progress_handle(&mut self, handle: ProgressHandle)
Attach a progress handle for idle timeout tracking.
This is called by the executor before running a node with an idle timeout policy. Nodes do not need to call this directly.
Sourcepub fn progress_handle(&self) -> Option<&ProgressHandle>
pub fn progress_handle(&self) -> Option<&ProgressHandle>
Get a reference to the attached progress handle, if any.