Rename old router to legacy_base_router (#2048)

Co-authored-by: Suchintan Singh <suchintansingh@gmail.com>
This commit is contained in:
Shuchang Zheng
2025-03-30 23:57:54 -07:00
committed by GitHub
parent 0107054a75
commit 83ad2adabd
15 changed files with 412 additions and 476 deletions

View File

@@ -101,16 +101,16 @@ class PersistentSessionsManager:
await self.database.mark_persistent_browser_session_deleted(session_id, organization_id)
self._browser_sessions.pop(session_id, None)
async def close_session(self, organization_id: str, session_id: str) -> None:
async def close_session(self, organization_id: str, browser_session_id: str) -> None:
"""Close a specific browser session."""
browser_session = self._browser_sessions.get(session_id)
browser_session = self._browser_sessions.get(browser_session_id)
if browser_session:
LOG.info(
"Closing browser session",
organization_id=organization_id,
session_id=session_id,
session_id=browser_session_id,
)
self._browser_sessions.pop(session_id, None)
self._browser_sessions.pop(browser_session_id, None)
try:
await browser_session.browser_state.close()
@@ -118,23 +118,23 @@ class PersistentSessionsManager:
LOG.info(
"Browser context already closed",
organization_id=organization_id,
session_id=session_id,
session_id=browser_session_id,
)
except Exception:
LOG.warning(
"Error while closing browser session",
organization_id=organization_id,
session_id=session_id,
session_id=browser_session_id,
exc_info=True,
)
else:
LOG.info(
"Browser session not found in memory, marking as deleted in database",
organization_id=organization_id,
session_id=session_id,
session_id=browser_session_id,
)
await self.database.mark_persistent_browser_session_deleted(session_id, organization_id)
await self.database.mark_persistent_browser_session_deleted(browser_session_id, organization_id)
async def close_all_sessions(self, organization_id: str) -> None:
"""Close all browser sessions for an organization."""

View File

@@ -2,24 +2,37 @@ from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel
from pydantic import BaseModel, Field
from skyvern.forge.sdk.schemas.persistent_browser_sessions import PersistentBrowserSession
class BrowserSessionResponse(BaseModel):
session_id: str
organization_id: str
runnable_type: str | None = None
runnable_id: str | None = None
created_at: datetime
modified_at: datetime
deleted_at: datetime | None = None
"""Response model for browser session information."""
browser_session_id: str = Field(description="Unique identifier for the browser session")
organization_id: str = Field(description="ID of the organization that owns this session")
runnable_type: str | None = Field(
None, description="Type of runnable associated with this session (workflow, task etc)"
)
runnable_id: str | None = Field(None, description="ID of the associated runnable")
created_at: datetime = Field(description="Timestamp when the session was created")
modified_at: datetime = Field(description="Timestamp when the session was last modified")
deleted_at: datetime | None = Field(None, description="Timestamp when the session was deleted, if applicable")
@classmethod
def from_browser_session(cls, browser_session: PersistentBrowserSession) -> BrowserSessionResponse:
"""
Creates a BrowserSessionResponse from a PersistentBrowserSession object.
Args:
browser_session: The persistent browser session to convert
Returns:
BrowserSessionResponse: The converted response object
"""
return cls(
session_id=browser_session.persistent_browser_session_id,
browser_session_id=browser_session.persistent_browser_session_id,
organization_id=browser_session.organization_id,
runnable_type=browser_session.runnable_type,
runnable_id=browser_session.runnable_id,