diff --git a/ft-app/app/collector.py b/ft-app/app/collector.py index 05f320f..17f73b0 100644 --- a/ft-app/app/collector.py +++ b/ft-app/app/collector.py @@ -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: diff --git a/ft-app/app/templates/admin.html b/ft-app/app/templates/admin.html index b5700ed..7c2aa0f 100644 --- a/ft-app/app/templates/admin.html +++ b/ft-app/app/templates/admin.html @@ -265,7 +265,14 @@ function startSync(url) { fetch(url, { method: 'POST' }) .then(function(r) { return r.json(); }) .then(function(data) { - if (!data.ok) { hideProgress(); return; } + if (!data.ok) { + document.getElementById('sync-progress-label').textContent = '已有同步任务进行中,请稍后再试'; + document.getElementById('sync-progress-pct').textContent = ''; + document.getElementById('sync-progress-bar').style.width = '0%'; + document.getElementById('sync-progress').insertAdjacentHTML('beforeend', + ''); + return; + } syncTimer = setInterval(pollProgress, 500); }); }