fix: stop simulation always updates DB status

- Status was only updated if engine was in memory (race condition)
- Now always sets status to 'stopped' in DB
- Returns 'stopped' instead of 'stopping'
- Cleaned up 3 stale running simulations in DB
This commit is contained in:
shokollm
2026-04-12 00:15:41 +00:00
parent 52adc93b25
commit b0131aa566

View File

@@ -272,10 +272,15 @@ def stop_simulation(
status_code=status.HTTP_404_NOT_FOUND, detail="Simulation not found" status_code=status.HTTP_404_NOT_FOUND, detail="Simulation not found"
) )
# Always update status to stopped, even if engine is not in memory
simulation.status = "stopped"
# Try to stop the engine if it's still in memory
if run_id in running_simulations: if run_id in running_simulations:
engine = running_simulations[run_id] engine = running_simulations[run_id]
engine.stop() engine.stop()
simulation.status = "stopped" del running_simulations[run_id]
db.commit()
db.commit()
return {"status": "stopping", "run_id": run_id} return {"status": "stopped", "run_id": run_id}