From 9fd0116dec35279c802eb0df0d06ba79f3b3a954 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 25 Jul 2026 21:40:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=90=8C=E6=AD=A5=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=B6=85=E6=97=B6=E5=90=8E=E5=8F=AF=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=EF=BC=8C=E5=89=8D=E7=AB=AF=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E6=97=B6=E6=98=BE=E7=A4=BA=E6=8F=90=E7=A4=BA=E8=80=8C=E9=9D=9E?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- ft-app/app/collector.py | 10 +++++++--- ft-app/app/templates/admin.html | 9 ++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) 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); }); }