Skip to main content

ExecutionSession

Struct ExecutionSession 

Source
pub struct ExecutionSession<S: WorkflowState = State, M: MergeStrategy<S> = StateMerge>
where S::Checkpoint: Debug,
{ /* private fields */ }
Expand description

执行会话 — 持有 State 所有权 + FrameStack + Graph 引用。

§职责

  • 持有 State 所有权(Engine 只是借用)
  • 管理 FrameStack(Subgraph 执行时 push/pop)
  • 创建和恢复 SessionCheckpoint

§设计原则

Graph 是 Immutable 的,多个 Session 共享同一个 Graph 实例。 Session 不拥有 Graph,只持有 Arc<Graph> 引用。

Runtime
└── Arc<Graph>

Session1 ──┐
Session2 ──┼── Arc<Graph>
Session3 ──┘

Implementations§

Source§

impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>
where S::Checkpoint: Debug,

Source

pub fn new(state: S, graph: Arc<Graph<S, M>>) -> Self

创建新的执行会话。

Source

pub fn restore( checkpoint: SessionCheckpoint<S>, graph: Arc<Graph<S, M>>, ) -> Result<Self, SessionError>

从 Checkpoint 恢复。

§P0-1: 使用 restore() 恢复 State

S::restore(checkpoint.state) 从 checkpoint snapshot 恢复完整 Runtime State。

§Graph 参数

调用方负责提供 Arc<Graph>(从 Runtime 获取), Session 不负责存储或查找 Graph。

§错误

如果 checkpoint.graph_hashgraph.canonical_hash() 不匹配, 返回 SessionError::GraphMismatch,拒绝恢复。

Source

pub fn checkpoint(&self) -> SessionCheckpoint<S>

创建 checkpoint — 保存当前执行位置 + 状态投影。

§P0-1: 使用 snapshot() 进行投影

state.snapshot() 返回 S::Checkpoint,只序列化必要字段。

§P0-2: 使用 canonical_hash

graph.canonical_hash() 从 DSL 层计算,不依赖 HashMap 顺序。

Source

pub fn state(&self) -> &S

获取状态引用。

Source

pub fn state_mut(&mut self) -> &mut S

获取状态可变引用。

Source

pub fn frame_stack(&self) -> &FrameStack<S>

获取帧栈引用。

Source

pub fn frame_stack_mut(&mut self) -> &mut FrameStack<S>

获取帧栈可变引用(用于 Subgraph 执行时 push/pop)。

Source

pub fn graph(&self) -> &Graph<S, M>

获取图引用。

Source

pub fn graph_arc(&self) -> Arc<Graph<S, M>>

获取图的 Arc 引用(用于共享)。

Source

pub fn into_state(self) -> S

消费会话,返回最终状态。

Source

pub fn into_parts(self) -> (S, FrameStack<S>)

消费会话,返回 (状态, 帧栈)。

Source§

impl<S: WorkflowState, M: MergeStrategy<S>> ExecutionSession<S, M>
where S::Checkpoint: Debug,

Source

pub async fn run_with( &mut self, engine: &mut ExecutionEngine<'_, S>, ) -> Result<(), GraphError>

使用指定的 Engine 执行。

Session 不知道 Stream,Engine 才知道 Stream。 职责分离:Session 负责 state + frame_stack,Engine 负责执行 + stream。

§示例
let mut engine = ExecutionEngine::new(
    &mut session.state,
    Some(stream),  // Stream 由调用者提供
    cancel,
);
session.run_with(&mut engine).await?;

Trait Implementations§

Source§

impl<S, M: MergeStrategy<S>> Default for ExecutionSession<S, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S = State, M = StateMerge> !RefUnwindSafe for ExecutionSession<S, M>

§

impl<S = State, M = StateMerge> !UnwindSafe for ExecutionSession<S, M>

§

impl<S, M> Freeze for ExecutionSession<S, M>
where S: Freeze,

§

impl<S, M> Send for ExecutionSession<S, M>

§

impl<S, M> Sync for ExecutionSession<S, M>
where <S as WorkflowState>::Checkpoint: Sync,

§

impl<S, M> Unpin for ExecutionSession<S, M>
where S: Unpin, <S as WorkflowState>::Checkpoint: Unpin,

§

impl<S, M> UnsafeUnpin for ExecutionSession<S, M>
where S: UnsafeUnpin,

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 = Infallible

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