pub struct DistributedSessionManager { /* private fields */ }Expand description
Manages concurrent distributed inference sessions.
The manager is cheap to clone because all state is held behind an
Arc-guarded lock. Clone the manager to share it across threads or
async tasks.
§Thread safety
All public methods acquire a short-lived read or write lock on the internal registry. Metrics are updated via lock-free atomics.
Implementations§
Source§impl DistributedSessionManager
impl DistributedSessionManager
Sourcepub fn create_session(
&self,
goal: &str,
peers: Vec<PeerId>,
) -> Result<SessionId, SessionError>
pub fn create_session( &self, goal: &str, peers: Vec<PeerId>, ) -> Result<SessionId, SessionError>
Create a new distributed inference session.
§Errors
SessionError::CapacityExceededwhen there are alreadyMAX_CONCURRENT_SESSIONSactive sessions.SessionError::IdGenerationwhen OS entropy is unavailable.
Sourcepub fn set_running(&self, id: &SessionId) -> Result<(), SessionError>
pub fn set_running(&self, id: &SessionId) -> Result<(), SessionError>
Transition a session to SessionStatus::Running.
Only valid from the SessionStatus::Pending state.
§Errors
SessionError::NotFoundwhenidis not registered.SessionError::InvalidTransitionwhen the current state is notPending.
Sourcepub fn set_completed(
&self,
id: &SessionId,
result_cid: Option<String>,
) -> Result<(), SessionError>
pub fn set_completed( &self, id: &SessionId, result_cid: Option<String>, ) -> Result<(), SessionError>
Transition a session to SessionStatus::Completed.
Valid from either Pending or Running.
§Errors
SessionError::NotFoundwhenidis not registered.SessionError::InvalidTransitionwhen the state is notPendingorRunning.
Sourcepub fn set_failed(
&self,
id: &SessionId,
reason: impl Into<String>,
) -> Result<(), SessionError>
pub fn set_failed( &self, id: &SessionId, reason: impl Into<String>, ) -> Result<(), SessionError>
Transition a session to SessionStatus::Failed.
Valid from either Pending or Running.
§Errors
SessionError::NotFoundwhenidis not registered.SessionError::InvalidTransitionwhen the state is terminal.
Sourcepub fn cancel_session(&self, id: &SessionId) -> Result<(), SessionError>
pub fn cancel_session(&self, id: &SessionId) -> Result<(), SessionError>
Cancel a session.
The session is transitioned to SessionStatus::Cancelled. Only
non-terminal sessions (Pending, Running) may be cancelled.
§Errors
SessionError::NotFoundwhenidis not registered.SessionError::InvalidTransitionwhen the session is already in a terminal state.
Sourcepub fn session_status(&self, id: &SessionId) -> Option<SessionStatus>
pub fn session_status(&self, id: &SessionId) -> Option<SessionStatus>
Return the current status of a session, or None if it does not exist.
Sourcepub fn session_goal(&self, id: &SessionId) -> Option<String>
pub fn session_goal(&self, id: &SessionId) -> Option<String>
Return the goal string associated with a session.
Sourcepub fn session_peers(&self, id: &SessionId) -> Option<Vec<PeerId>>
pub fn session_peers(&self, id: &SessionId) -> Option<Vec<PeerId>>
Return the peers associated with a session.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Return the number of sessions currently in the registry.
This includes both active and terminal (Completed / Failed / Cancelled) sessions that have not yet been garbage-collected.
Sourcepub fn gc_expired_sessions(&self, max_age: Duration) -> usize
pub fn gc_expired_sessions(&self, max_age: Duration) -> usize
Remove sessions whose created_at age exceeds max_age.
This includes sessions in any state (Pending, Running, Completed, Failed, Cancelled) that are older than the threshold. The method returns the number of sessions that were removed.
Sourcepub fn metrics(&self) -> &SessionMetrics
pub fn metrics(&self) -> &SessionMetrics
Return a reference to the live metrics object.
Use SessionMetrics::snapshot to get a plain-value copy.
Trait Implementations§
Source§impl Clone for DistributedSessionManager
impl Clone for DistributedSessionManager
Source§fn clone(&self) -> DistributedSessionManager
fn clone(&self) -> DistributedSessionManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DistributedSessionManager
impl Debug for DistributedSessionManager
Auto Trait Implementations§
impl !RefUnwindSafe for DistributedSessionManager
impl !UnwindSafe for DistributedSessionManager
impl Freeze for DistributedSessionManager
impl Send for DistributedSessionManager
impl Sync for DistributedSessionManager
impl Unpin for DistributedSessionManager
impl UnsafeUnpin for DistributedSessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more