Refresh external benchmark priors off the request path. Providers still enforce their own TTLs, so this loop is cheap when cached data is fresh and avoids blocking live routing on network calls.
()
| 2985 | logger.warning("Rediscovery failed: %s", exc) |
| 2986 | |
| 2987 | async def _benchmark_refresh_loop() -> None: |
| 2988 | """Refresh external benchmark priors off the request path. |
| 2989 | |
| 2990 | Providers still enforce their own TTLs, so this loop is cheap when |
| 2991 | cached data is fresh and avoids blocking live routing on network calls. |
| 2992 | """ |
| 2993 | import asyncio |
| 2994 | interval = float(os.environ.get("UNCOMMON_ROUTE_BENCHMARK_REFRESH_INTERVAL", "3600")) |
| 2995 | if interval <= 0: |
| 2996 | return |
| 2997 | while True: |
| 2998 | await asyncio.sleep(interval) |
| 2999 | try: |
| 3000 | from uncommon_route.benchmark import get_benchmark_cache |
| 3001 | count = await get_benchmark_cache().refresh() |
| 3002 | if count > 0: |
| 3003 | logger.info("Benchmark refresh: %d models updated", count) |
| 3004 | except Exception as exc: # noqa: BLE001 |
| 3005 | logger.warning("Benchmark refresh failed: %s", exc) |
| 3006 | |
| 3007 | def _selector_state( |
| 3008 | *, |
no test coverage detected