后台同步任务超时后可覆盖启动,前端阻塞时显示提示而非静默隐藏

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 21:40:11 +08:00
parent ab9b132c69
commit 9fd0116dec
2 changed files with 15 additions and 4 deletions
+7 -3
View File
@@ -1,13 +1,16 @@
"""Data collector — fetch OHLCV from akshare and upsert into daily_bars."""
import threading
import time
from datetime import date
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, "error": ""}
_progress = {"running": False, "label": "", "done": 0, "total": 0, "result": 0, "finished": False, "error": "", "started_at": 0}
_lock = threading.Lock()
STALE_SECONDS = 120
def get_progress() -> dict:
with _lock:
@@ -16,9 +19,10 @@ def get_progress() -> dict:
def _start_bg(target, label):
with _lock:
if _progress["running"]:
now = time.time()
if _progress["running"] and (now - _progress["started_at"]) < STALE_SECONDS:
return False
_progress.update(running=True, finished=False, label=label, done=0, total=0, error="")
_progress.update(running=True, finished=False, label=label, done=0, total=0, error="", started_at=now)
def _run():
try: