修复中控轮询连锁唤醒导致 CPU 居高不下:轮询加最小间隔并取消 board 每轮强制刷新看板。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-25 12:35:41 +08:00
parent 75f50fe083
commit b63f6f0962
8 changed files with 131 additions and 35 deletions
+7 -8
View File
@@ -11,6 +11,7 @@ from dataclasses import dataclass
from typing import Any
from hub_board_cache import board_store
from lib.hub.hub_poll_wait_lib import wait_poll_interval
HUB_CHART_POLL_INTERVAL = float(os.getenv("HUB_CHART_POLL_INTERVAL", "5"))
HUB_CHART_SSE_HEARTBEAT_SEC = float(os.getenv("HUB_CHART_SSE_HEARTBEAT_SEC", "25"))
@@ -161,18 +162,16 @@ class ChartPollStore:
async def _loop(self) -> None:
assert self._poll_fn is not None
while not self._stop.is_set():
started = time.monotonic()
await self._poll_once(self._poll_fn)
if self._stop.is_set():
break
self._refresh.clear()
sleep_task = asyncio.create_task(asyncio.sleep(HUB_CHART_POLL_INTERVAL))
refresh_task = asyncio.create_task(self._refresh.wait())
done, pending = await asyncio.wait(
{sleep_task, refresh_task},
return_when=asyncio.FIRST_COMPLETED,
await wait_poll_interval(
refresh=self._refresh,
stop=self._stop,
interval_sec=HUB_CHART_POLL_INTERVAL,
started_at=started,
)
for t in pending:
t.cancel()
async def _poll_once(self, poll_fn: PollFn) -> None:
async with self._lock: