22 lines
666 B
Python
22 lines
666 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from yuxi.channels.models import HealthStatus
|
||
|
|
|
||
|
|
|
||
|
|
async def probe_bridge(bridge) -> HealthStatus:
|
||
|
|
return await bridge.health_check()
|
||
|
|
|
||
|
|
|
||
|
|
async def wait_for_connection(bridge, timeout: float = 30.0) -> dict[str, Any]:
|
||
|
|
import asyncio
|
||
|
|
|
||
|
|
deadline = asyncio.get_event_loop().time() + timeout
|
||
|
|
while asyncio.get_event_loop().time() < deadline:
|
||
|
|
health = await bridge.health_check()
|
||
|
|
if health.status == "healthy":
|
||
|
|
return {"connected": True, "jid": health.metadata.get("jid", "")}
|
||
|
|
await asyncio.sleep(1.0)
|
||
|
|
return {"connected": False, "error": "Connection timeout"}
|