feat: add availability check for sandbox in Shipyard and base booters

This commit is contained in:
Soulter
2026-01-13 20:02:18 +08:00
parent 0a58eaecdd
commit 661bcfd890
3 changed files with 22 additions and 0 deletions
+4
View File
@@ -21,3 +21,7 @@ class SandboxBooter:
Should return a dict with `success` (bool) and `file_path` (str) keys.
"""
...
async def available(self) -> bool:
"""Check if the sandbox is available."""
...
+13
View File
@@ -61,3 +61,16 @@ class ShipyardBooter(SandboxBooter):
async def upload_file(self, path: str, file_name: str) -> dict:
"""Upload file to sandbox"""
return await self._ship.upload_file(path, file_name)
async def available(self) -> bool:
"""Check if the sandbox is available."""
try:
ship_id = self._ship.id
data = await self._sandbox_client.client.get_ship(ship_id)
if not data:
return False
health = bool(data.get("status", 0) == 1)
return health
except Exception as e:
logger.error(f"Error checking Shipyard sandbox availability: {e}")
return False
+5
View File
@@ -15,6 +15,11 @@ class SandboxClient:
session_id: str,
booter_type: Literal["shipyard", "boxlite"] = "shipyard",
) -> SandboxBooter:
if session_id in session_booter:
booter = session_booter[session_id]
if not await booter.available():
# rebuild
session_booter.pop(session_id, None)
if session_id not in session_booter:
uuid_str = uuid.uuid5(uuid.NAMESPACE_DNS, session_id).hex
if booter_type == "shipyard":