Skip to main content

NodeContext

Struct NodeContext 

Source
pub struct NodeContext {
    pub state: State,
    pub config: ExecutionConfig,
    pub step: usize,
    /* private fields */
}
Expand description

Context passed to nodes during execution

Fields§

§state: State

Current graph state (read-only view)

§config: ExecutionConfig

Configuration for this execution

§step: usize

Current step number

Implementations§

Source§

impl NodeContext

Source

pub fn new(state: State, config: ExecutionConfig, step: usize) -> Self

Create a new node context

Source

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.

Source

pub fn set_parent_schema(&mut self, schema: Arc<StateSchema>)

Attaches the running graph’s schema.

Source

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.

Source

pub async fn run_node_with( &self, child: &str, input: Value, options: RunNodeOptions, ) -> Result<Value>

Invoke another node with an explicit run id.

§Errors

As run_node, and additionally when this node was not given the ability to invoke children.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get a value from state

Source

pub fn get_as<T: DeserializeOwned>(&self, key: &str) -> Option<T>

Get a value from state as a specific type

Source

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())
}
Source

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.

Source

pub fn progress_handle(&self) -> Option<&ProgressHandle>

Get a reference to the attached progress handle, if any.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more