generated from coulomb/repo-seed
feat: implement OpsBridge CLI (BRIDGE-WP-0001)
Full TDD implementation of the `bridge` CLI tool covering all phases from BRIDGE-WP-0001: project scaffolding, config loading, state management, audit logging, health checks, tunnel lifecycle manager, and all CLI commands (up/down/restart/status/logs). 77 tests, all green. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
31
src/bridge/health.py
Normal file
31
src/bridge/health.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""HTTP health checker for OpsBridge."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
|
||||
|
||||
@dataclass
|
||||
class HealthResult:
|
||||
ok: bool
|
||||
status_code: Optional[int] = None
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
class HealthChecker:
|
||||
def __init__(self, url: str, timeout_seconds: int = 5):
|
||||
self._url = url
|
||||
self._timeout = timeout_seconds
|
||||
|
||||
async def check(self) -> HealthResult:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
||||
response = await client.get(self._url)
|
||||
response.raise_for_status()
|
||||
return HealthResult(ok=True, status_code=response.status_code)
|
||||
except httpx.HTTPStatusError as e:
|
||||
return HealthResult(ok=False, status_code=e.response.status_code, error=str(e))
|
||||
except Exception as e:
|
||||
return HealthResult(ok=False, error=str(e))
|
||||
Reference in New Issue
Block a user