pub struct SessionLifecycleManager { /* private fields */ }Expand description
Manages session lifecycles with automatic cleanup and recovery.
Tracks active sessions and enforces limits on duration, message count, and inactivity. Integrates with lock and affinity management to ensure proper resource cleanup when sessions are forcibly closed.
§Thread Safety
All operations are async and use Arc<RwLock<>> for thread-safe access.
§Examples
use queue_runtime::{SessionLifecycleManager, SessionId, SessionLifecycleConfig};
use std::time::Duration;
let config = SessionLifecycleConfig::default();
let manager = SessionLifecycleManager::new(config);
let session_id = SessionId::new("order-456".to_string())?;
// Start tracking a session
manager.start_session(session_id.clone(), "worker-1".to_string()).await?;
// Record activity
manager.record_message(&session_id).await?;
// Check if session should be closed
let should_close = manager.should_close_session(&session_id).await;Implementations§
Source§impl SessionLifecycleManager
impl SessionLifecycleManager
Sourcepub fn new(config: SessionLifecycleConfig) -> Self
pub fn new(config: SessionLifecycleConfig) -> Self
Create a new session lifecycle manager with the given configuration.
Sourcepub async fn start_session(
&self,
session_id: SessionId,
consumer_id: String,
) -> Result<(), QueueError>
pub async fn start_session( &self, session_id: SessionId, consumer_id: String, ) -> Result<(), QueueError>
Start tracking a new session.
§Errors
Returns QueueError::ValidationError if session is already being tracked.
Sourcepub async fn stop_session(
&self,
session_id: &SessionId,
) -> Result<(), QueueError>
pub async fn stop_session( &self, session_id: &SessionId, ) -> Result<(), QueueError>
Stop tracking a session.
§Errors
Returns QueueError::SessionNotFound if session is not being tracked.
Sourcepub async fn record_message(
&self,
session_id: &SessionId,
) -> Result<(), QueueError>
pub async fn record_message( &self, session_id: &SessionId, ) -> Result<(), QueueError>
Record message processing activity for a session.
Increments message count and updates last activity timestamp.
§Errors
Returns QueueError::SessionNotFound if session is not being tracked.
Sourcepub async fn touch_session(
&self,
session_id: &SessionId,
) -> Result<(), QueueError>
pub async fn touch_session( &self, session_id: &SessionId, ) -> Result<(), QueueError>
Update last activity timestamp without incrementing message count.
§Errors
Returns QueueError::SessionNotFound if session is not being tracked.
Sourcepub async fn get_session_info(
&self,
session_id: &SessionId,
) -> Option<SessionInfo>
pub async fn get_session_info( &self, session_id: &SessionId, ) -> Option<SessionInfo>
Get information about a session.
Returns None if session is not being tracked.
Sourcepub async fn should_close_session(&self, session_id: &SessionId) -> bool
pub async fn should_close_session(&self, session_id: &SessionId) -> bool
Check if a session should be closed based on configured limits.
A session should be closed if:
- It has exceeded the maximum duration
- It has processed more than the maximum message count
- It has been idle longer than the timeout
Returns false if session is not being tracked.
Sourcepub async fn get_sessions_to_close(&self) -> Vec<SessionId>
pub async fn get_sessions_to_close(&self) -> Vec<SessionId>
Get all sessions that should be closed based on configured limits.
Returns a list of session IDs that have exceeded limits.
Sourcepub async fn cleanup_expired_sessions(&self) -> Vec<SessionId>
pub async fn cleanup_expired_sessions(&self) -> Vec<SessionId>
Sourcepub async fn session_count(&self) -> usize
pub async fn session_count(&self) -> usize
Get the total number of active sessions.
Sourcepub async fn get_active_sessions(&self) -> Vec<SessionId>
pub async fn get_active_sessions(&self) -> Vec<SessionId>
Get all active session IDs.
Sourcepub async fn get_consumer_sessions(&self, consumer_id: &str) -> Vec<SessionId>
pub async fn get_consumer_sessions(&self, consumer_id: &str) -> Vec<SessionId>
Get all sessions for a specific consumer.
Trait Implementations§
Source§impl Clone for SessionLifecycleManager
impl Clone for SessionLifecycleManager
Source§fn clone(&self) -> SessionLifecycleManager
fn clone(&self) -> SessionLifecycleManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more