-
Notifications
You must be signed in to change notification settings - Fork 144
feat (sandbox): Unify container session management with Redis-backed SessionManager and add workspace filesystem facade (SandboxFS) #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
b6c6081
e7c58a0
879ba5f
bf51f1c
263925f
e40fd65
4b46b81
2009b4f
f5dc405
aa8b747
d6b7b97
1a7372a
c52b4d6
863129d
11e8bd2
d23891a
acfdb6f
e62644f
2aafc5f
ba45229
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import logging | ||
| from typing import Dict, Optional, List | ||
|
|
||
| from ..collections import RedisMapping, InMemoryMapping | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class SessionManager: | ||
| """Manager for sessions that handles creation, retrieval, | ||
| updating, and deletion of sessions. | ||
| """ | ||
|
|
||
| def __init__(self, config): | ||
| """Initialize the session manager with an empty session dictionary.""" | ||
| self.config = config | ||
|
|
||
| if self.config.redis_enabled: | ||
| import redis | ||
|
|
||
| redis_client = redis.Redis( | ||
| host=self.config.redis_server, | ||
| port=self.config.redis_port, | ||
| db=self.config.redis_db, | ||
| username=self.config.redis_user, | ||
| password=self.config.redis_password, | ||
| decode_responses=True, | ||
| ) | ||
| try: | ||
| redis_client.ping() | ||
| except ConnectionError as e: | ||
| raise RuntimeError( | ||
| "Unable to connect to the Redis server.", | ||
| ) from e | ||
|
|
||
| self.sessions = RedisMapping( | ||
| redis_client, | ||
| prefix="container_session_manager", # TODO: Configurable | ||
| ) | ||
| else: | ||
| self.sessions = InMemoryMapping() | ||
|
|
||
| logger.debug("Session Manager initialized") | ||
|
|
||
| def create_session(self, session_id: str, session_data: Dict): | ||
| """Create a new session with the given session_id and session_data.""" | ||
| self.sessions.set(session_id, session_data) | ||
| logger.debug(f"Created session: {session_id}") | ||
|
rayrayraykk marked this conversation as resolved.
|
||
|
|
||
| def get_session(self, session_id: str) -> Optional[Dict]: | ||
| """Retrieve session data by session_id.""" | ||
| return self.sessions.get(session_id) | ||
|
rayrayraykk marked this conversation as resolved.
|
||
|
|
||
| def update_session(self, session_id: str, updates: Dict): | ||
| """Update an existing session with new data.""" | ||
| if self.sessions.get(session_id): | ||
| self.sessions.set(session_id, updates) | ||
|
rayrayraykk marked this conversation as resolved.
|
||
| logger.debug(f"Updated session: {session_id}") | ||
|
rayrayraykk marked this conversation as resolved.
Comment on lines
+55
to
+59
|
||
|
|
||
| def delete_session(self, session_id: str): | ||
| """Delete a session by session_id.""" | ||
| if self.sessions.get(session_id): | ||
| self.sessions.delete(session_id) | ||
| logger.debug(f"Deleted session: {session_id}") | ||
|
rayrayraykk marked this conversation as resolved.
|
||
|
|
||
| def list_sessions(self) -> List[str]: | ||
| """List all session IDs.""" | ||
| return list(self.sessions.scan()) | ||
|
rayrayraykk marked this conversation as resolved.
rayrayraykk marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.