Scale biz_state collects with dedicated workers and non-blocking UI poll.

Add PG claim/NE mutex, persist pool, and biz_state_worker replicas; fix double-SSH and row-count bugs; stop 32m collectNow while-loop from freezing page switches.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-22 17:00:37 +08:00
parent 0eb65a839e
commit 3a0de0d7fb
22 changed files with 1210 additions and 165 deletions

View file

@ -27,7 +27,9 @@ def recover_interrupted_collects_on_startup(db: Session) -> dict[str, Any]:
task_n = 0
stuck_batches = (
db.query(BizStateBatch).filter(BizStateBatch.status == "running").all()
db.query(BizStateBatch)
.filter(BizStateBatch.status.in_(("running", "queued")))
.all()
)
for b in stuck_batches:
b.status = "partial"
@ -58,6 +60,8 @@ def recover_interrupted_collects_on_startup(db: Session) -> dict[str, Any]:
)
for t in stuck_tasks:
t.collect_running = False
if hasattr(t, "collect_queued_at"):
t.collect_queued_at = None
if not t.last_collect_ended_at:
t.last_collect_ended_at = now
err = str(t.last_error or "").strip()