Background STL analysis with computing spinner; manual geometry override
- analyse_in_background() runs in FastAPI BackgroundTasks with its own DB session; _in_progress set prevents duplicate concurrent analyses - Job detail shows a spinner + auto-reloads every 3s while computing - 'Compute now' button also triggers background analysis - StlCache.manually_set flag (migration 0011): entries marked manual are never overwritten by auto-analysis - 'Override values' collapsible form on job detail lets user set bounding box and volume directly from slicer data Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from app.models.stl_cache import StlCache
|
||||
logger = logging.getLogger("pops")
|
||||
|
||||
_ANALYSABLE = {".stl", ".3mf"}
|
||||
_in_progress: set[str] = set()
|
||||
|
||||
|
||||
def analyse(filename: str, db: Session) -> StlCache | None:
|
||||
@@ -45,6 +46,26 @@ def analyse(filename: str, db: Session) -> StlCache | None:
|
||||
return None
|
||||
|
||||
|
||||
def analyse_in_background(filename: str) -> None:
|
||||
"""Run analyse() in a background task with its own DB session."""
|
||||
if filename in _in_progress:
|
||||
return
|
||||
_in_progress.add(filename)
|
||||
try:
|
||||
from app.db import SessionLocal
|
||||
db = SessionLocal()
|
||||
try:
|
||||
analyse(filename, db)
|
||||
finally:
|
||||
db.close()
|
||||
finally:
|
||||
_in_progress.discard(filename)
|
||||
|
||||
|
||||
def is_computing(filename: str) -> bool:
|
||||
return filename in _in_progress
|
||||
|
||||
|
||||
def get_cache_map(filenames: list[str], db: Session) -> dict[str, StlCache]:
|
||||
"""Bulk-fetch cached entries for a list of filenames."""
|
||||
rows = db.query(StlCache).filter(StlCache.filename.in_(filenames)).all()
|
||||
|
||||
Reference in New Issue
Block a user