From d1f2ebaf8871ed95dbf184da73686089689dac05 Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 14 Mar 2025 18:21:11 -0700 Subject: [PATCH] remove healthcheck ping --- stagehand/client.py | 43 ++++------------------------------------ stagehand/sync/client.py | 36 ++++----------------------------- 2 files changed, 8 insertions(+), 71 deletions(-) diff --git a/stagehand/client.py b/stagehand/client.py index ab444f82..3ad579fa 100644 --- a/stagehand/client.py +++ b/stagehand/client.py @@ -151,14 +151,15 @@ async def init(self): timeout=self.timeout_settings ) - # Check server health - await self._check_server_health() - # Create session if we don't have one if not self.session_id: await self._create_session() self._log(f"Created new session: {self.session_id}", level=3) + ### + # TODO: throw log for unauthorized (401) key not whitelisted + ### + # Start Playwright and connect to remote self._log("Starting Playwright...", level=3) self._playwright = await async_playwright().start() @@ -237,42 +238,6 @@ async def close(self): self._closed = True - async def _check_server_health(self, timeout: int = 10): - """ - Ping /healthcheck to verify the server is available. - Uses exponential backoff for retries. - """ - start = time.time() - attempt = 0 - while True: - try: - client = self.httpx_client or httpx.AsyncClient( - timeout=self.timeout_settings - ) - async with client: - headers = { - "x-bb-api-key": self.browserbase_api_key, - } - resp = await client.get( - f"{self.server_url}/healthcheck", headers=headers - ) - if resp.status_code == 200: - data = resp.json() - if data.get("status") == "ok": - self._log("Healthcheck passed. Server is running.", level=3) - return - except Exception as e: - self._log(f"Healthcheck error: {str(e)}", level=3) - - if time.time() - start > timeout: - raise TimeoutError(f"Server not responding after {timeout} seconds.") - - wait_time = min( - 2**attempt * 0.5, 5.0 - ) # Exponential backoff, capped at 5 seconds - await asyncio.sleep(wait_time) - attempt += 1 - async def _create_session(self): """ Create a new session by calling /sessions/start on the server. diff --git a/stagehand/sync/client.py b/stagehand/sync/client.py index 9258ce1f..d0e0769c 100644 --- a/stagehand/sync/client.py +++ b/stagehand/sync/client.py @@ -72,14 +72,15 @@ def init(self): if not self._client: self._client = requests.Session() - # Check server health - self._check_server_health() - # Create session if we don't have one if not self.session_id: self._create_session() self._log(f"Created new session: {self.session_id}", level=3) + ### + # TODO: throw log for unauthorized (401) key not whitelisted + ### + # Start Playwright and connect to remote self._log("Starting Playwright...", level=3) self._playwright = sync_playwright().start() @@ -152,35 +153,6 @@ def close(self): self._closed = True - def _check_server_health(self, timeout: int = 10): - """ - Check server health synchronously with exponential backoff. - """ - start = time.time() - attempt = 0 - while True: - try: - headers = { - "x-bb-api-key": self.browserbase_api_key, - } - resp = self._client.get( - f"{self.server_url}/healthcheck", headers=headers - ) - if resp.status_code == 200: - data = resp.json() - if data.get("status") == "ok": - self._log("Healthcheck passed. Server is running.", level=3) - return - except Exception as e: - self._log(f"Healthcheck error: {str(e)}", level=3) - - if time.time() - start > timeout: - raise TimeoutError(f"Server not responding after {timeout} seconds.") - - wait_time = min(2**attempt * 0.5, 5.0) - time.sleep(wait_time) - attempt += 1 - def _create_session(self): """ Create a new session synchronously.