Просмотр исходного кода

Fix probe() dispatch — fall back to get_calendar for clients without probe()

ZiB 4 месяцев назад
Родитель
Сommit
7fc4c96bfd
2 измененных файлов с 9 добавлено и 8 удалено
  1. 7 1
      room_cal/_health.py
  2. 2 7
      room_cal/service_api/_protocols.py

+ 7 - 1
room_cal/_health.py

@@ -61,8 +61,14 @@ async def caldav_checks(calendar_name: str = DEFAULT_CALENDAR_NAME) -> tuple[Hea
 
 
 async def _probe_service(key: str, api: ServiceAPI) -> HealthResult:
+  from room_cal._utils import local_today
+  client = api._clients[key]
   try:
-    await api._clients[key].probe()
+    if hasattr(client, 'probe'):
+      await client.probe()
+    else:
+      today = local_today().isoformat()
+      await client.get_calendar(today, today)
     return HealthResult(ok=True)
   except ServiceAuthError as e:
     return HealthResult(ok=False, reason=str(e))

+ 2 - 7
room_cal/service_api/_protocols.py

@@ -10,13 +10,8 @@ class ServiceClient(Protocol):
   async def set_price(self, d: str, price: int) -> None: ...
   async def set_availability(self, d: str, available: bool) -> None: ...
   async def probe(self) -> None:
-    """Liveness check used by the health monitor. Raises ServiceAuthError on failure.
-    Default implementation calls get_calendar for today. Override for clients where
-    a live calendar fetch is not a reliable health signal.
-    """
-    from room_cal._utils import local_today
-    today = local_today().isoformat()
-    await self.get_calendar(today, today)
+    """Liveness check used by the health monitor. Raises ServiceAuthError on failure."""
+    ...
 
 
 @runtime_checkable