diff --git a/app/routers/qualys.py b/app/routers/qualys.py index b9fb635..9531ef6 100644 --- a/app/routers/qualys.py +++ b/app/routers/qualys.py @@ -1229,7 +1229,22 @@ async def qualys_dashboard_refresh(request: Request, db=Depends(get_db)): from app.database import SessionLocal s = SessionLocal() try: - compute_vuln_dashboard(s, triggered_by=f"manual:{user.get('sub','?')}", run_id=rid) + res = compute_vuln_dashboard(s, triggered_by=f"manual:{user.get('sub','?')}", run_id=rid) + # Filet : si compute n'a pas update le run (exception silenced), on le force + current = s.execute(text("SELECT status FROM qualys_vuln_snapshot_run WHERE id=:rid"), + {"rid": rid}).scalar() + if current == "pending": + msg = res.get("msg", "compute n'a pas update le run") if isinstance(res, dict) else "?" + s.execute(text("UPDATE qualys_vuln_snapshot_run SET status='error', msg=:m WHERE id=:rid"), + {"m": msg[:500], "rid": rid}) + s.commit() + except Exception as ex: + try: + s.execute(text("UPDATE qualys_vuln_snapshot_run SET status='error', msg=:m WHERE id=:rid"), + {"m": str(ex)[:500], "rid": rid}) + s.commit() + except Exception: + pass finally: s.close() threading.Thread(target=_runner, args=(run_id,), daemon=True).start() diff --git a/app/services/qualys_service.py b/app/services/qualys_service.py index 4cc1a25..e5ffdc8 100644 --- a/app/services/qualys_service.py +++ b/app/services/qualys_service.py @@ -892,11 +892,6 @@ def _is_scanned(asset_row, has_vuln_data): def compute_vuln_dashboard(db, triggered_by="manual", run_id=None): """Calcule un nouveau snapshot. Si run_id fourni, l'utilise (sinon en cree un). Retourne dict {ok, msg, run_id, asset_count, duration_sec}.""" - global _dashboard_running - if _dashboard_running: - return {"ok": False, "msg": "Calcul deja en cours", "run_id": None, - "asset_count": 0, "duration_sec": 0} - _dashboard_running = True import time t0 = time.time() try: @@ -1002,7 +997,7 @@ def compute_vuln_dashboard(db, triggered_by="manual", run_id=None): return {"ok": False, "msg": str(ex), "run_id": run_id, "asset_count": 0, "duration_sec": int(time.time() - t0)} finally: - _dashboard_running = False + pass def load_vuln_dashboard(db): diff --git a/app/templates/qualys_dashboard.html b/app/templates/qualys_dashboard.html index 8e3519e..ea1c75a 100644 --- a/app/templates/qualys_dashboard.html +++ b/app/templates/qualys_dashboard.html @@ -66,33 +66,33 @@ setTimeout(function() { window.location.href = '/qualys/dashboard'; }, 15000); {% set g = data.global %} -