后台同步异常时前端显示错误提示,不再卡住页面

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 21:34:04 +08:00
parent 012b220c60
commit 1b0f906640
2 changed files with 24 additions and 2 deletions
+5 -2
View File
@@ -5,7 +5,7 @@ from app.database import SessionLocal
from app.models import DailyBar, Contract
from app.engine.lock_strategy import compute_amp_5d
_progress = {"running": False, "label": "", "done": 0, "total": 0, "result": 0, "finished": False}
_progress = {"running": False, "label": "", "done": 0, "total": 0, "result": 0, "finished": False, "error": ""}
_lock = threading.Lock()
@@ -18,11 +18,14 @@ def _start_bg(target, label):
with _lock:
if _progress["running"]:
return False
_progress.update(running=True, finished=False, label=label, done=0, total=0)
_progress.update(running=True, finished=False, label=label, done=0, total=0, error="")
def _run():
try:
target()
except Exception as e:
with _lock:
_progress["error"] = str(e)
finally:
with _lock:
_progress["running"] = False