| 43 | |
| 44 | |
| 45 | class Sam3ServicePool: |
| 46 | def __init__(self, endpoints: List[str], timeout: int = 120) -> None: |
| 47 | if len(endpoints) == 0: |
| 48 | raise ValueError("At least one endpoint is required") |
| 49 | self.clients = [Sam3ServiceClient(url, timeout=timeout) for url in endpoints] |
| 50 | self._lock = threading.Lock() |
| 51 | self._cursor = itertools.cycle(range(len(self.clients))) |
| 52 | |
| 53 | def predict(self, *args, **kwargs) -> Dict: |
| 54 | with self._lock: |
| 55 | client_index = next(self._cursor) |
| 56 | return self.clients[client_index].predict(*args, **kwargs) |
| 57 | |
| 58 | def health(self) -> Dict[str, bool]: |
| 59 | status: Dict[str, bool] = {} |
| 60 | for client in self.clients: |
| 61 | try: |
| 62 | status[client.base_url] = client.health() |
| 63 | except Exception: |
| 64 | status[client.base_url] = False |
| 65 | return status |
nothing calls this directly
no outgoing calls
no test coverage detected