|
@@ -5,7 +5,6 @@ import random
|
|
|
from dataclasses import dataclass
|
|
from dataclasses import dataclass
|
|
|
from datetime import datetime, timezone
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
|
|
-from room_cal.store import Calendar
|
|
|
|
|
from room_cal.service_api import ServiceAPI
|
|
from room_cal.service_api import ServiceAPI
|
|
|
from room_cal.service_api.types import ServiceAuthError
|
|
from room_cal.service_api.types import ServiceAuthError
|
|
|
from room_cal._utils import services
|
|
from room_cal._utils import services
|
|
@@ -38,26 +37,14 @@ def get_cached() -> tuple[dict | None, bool]:
|
|
|
return _cached, age > _CACHE_TTL
|
|
return _cached, age > _CACHE_TTL
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def caldav_checks() -> tuple[HealthResult, HealthResult]:
|
|
|
|
|
- """Open one CalDAV connection and run both the connection and calendar-exists checks."""
|
|
|
|
|
- from room_cal._utils import get_config
|
|
|
|
|
- cfg = get_config()
|
|
|
|
|
- if cfg.store.active != 'caldav':
|
|
|
|
|
- return HealthResult(ok=True), HealthResult(ok=True)
|
|
|
|
|
- cal_cfg = cfg.store.caldav
|
|
|
|
|
- cal = Calendar(cal_cfg.calendar_name, url=cal_cfg.url, username=cal_cfg.username, password=cal_cfg.password)
|
|
|
|
|
|
|
+async def store_check() -> HealthResult:
|
|
|
|
|
+ """Ask the active store backend to report its own health."""
|
|
|
|
|
+ from room_cal.store import get_backend
|
|
|
try:
|
|
try:
|
|
|
- async with await cal._client() as client:
|
|
|
|
|
- conn = HealthResult(ok=True)
|
|
|
|
|
- try:
|
|
|
|
|
- await cal._get_calendar(client)
|
|
|
|
|
- cal_result = HealthResult(ok=True)
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- cal_result = HealthResult(ok=False, reason=str(e))
|
|
|
|
|
|
|
+ ok, reason = await get_backend().health_check()
|
|
|
|
|
+ return HealthResult(ok=ok, reason=reason)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- conn = HealthResult(ok=False, reason=str(e))
|
|
|
|
|
- cal_result = HealthResult(ok=False, reason='connection failed')
|
|
|
|
|
- return conn, cal_result
|
|
|
|
|
|
|
+ return HealthResult(ok=False, reason=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _probe_service(key: str, api: ServiceAPI) -> HealthResult:
|
|
async def _probe_service(key: str, api: ServiceAPI) -> HealthResult:
|
|
@@ -98,26 +85,25 @@ async def probe_once() -> None:
|
|
|
periodic_disabled = bool(os.getenv('DISABLE_PERIODIC'))
|
|
periodic_disabled = bool(os.getenv('DISABLE_PERIODIC'))
|
|
|
try:
|
|
try:
|
|
|
api = ServiceAPI()
|
|
api = ServiceAPI()
|
|
|
- conn, cal_result = await caldav_checks()
|
|
|
|
|
|
|
+ store_result = await store_check()
|
|
|
creds = {} if periodic_disabled else await credentials_checks(api)
|
|
creds = {} if periodic_disabled else await credentials_checks(api)
|
|
|
- caldav_ok = conn.ok and cal_result.ok
|
|
|
|
|
|
|
+ store_ok = store_result.ok
|
|
|
creds_ok = all(v.ok for v in creds.values())
|
|
creds_ok = all(v.ok for v in creds.values())
|
|
|
- if caldav_ok and creds_ok:
|
|
|
|
|
|
|
+ if store_ok and creds_ok:
|
|
|
overall = 'ok'
|
|
overall = 'ok'
|
|
|
- elif caldav_ok:
|
|
|
|
|
|
|
+ elif store_ok:
|
|
|
overall = 'degraded'
|
|
overall = 'degraded'
|
|
|
else:
|
|
else:
|
|
|
overall = 'error'
|
|
overall = 'error'
|
|
|
_cached = {
|
|
_cached = {
|
|
|
'status': overall,
|
|
'status': overall,
|
|
|
'checks': {
|
|
'checks': {
|
|
|
- 'caldav_connection': conn.to_dict(),
|
|
|
|
|
- 'calendar': cal_result.to_dict(),
|
|
|
|
|
|
|
+ 'store_connected': store_result.to_dict(),
|
|
|
'credentials': {k: v.to_dict() for k, v in creds.items()},
|
|
'credentials': {k: v.to_dict() for k, v in creds.items()},
|
|
|
},
|
|
},
|
|
|
'checked_at': datetime.now(timezone.utc).isoformat(),
|
|
'checked_at': datetime.now(timezone.utc).isoformat(),
|
|
|
}
|
|
}
|
|
|
- if caldav_ok and creds_ok:
|
|
|
|
|
|
|
+ if store_ok and creds_ok:
|
|
|
from room_cal._periodic import run_due, _register_all_periodics
|
|
from room_cal._periodic import run_due, _register_all_periodics
|
|
|
_register_all_periodics()
|
|
_register_all_periodics()
|
|
|
await run_due(api)
|
|
await run_due(api)
|