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:
@@ -272,10 +272,15 @@ def stop_simulation(
|
||||
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:
|
||||
engine = running_simulations[run_id]
|
||||
engine.stop()
|
||||
simulation.status = "stopped"
|
||||
db.commit()
|
||||
del running_simulations[run_id]
|
||||
|
||||
return {"status": "stopping", "run_id": run_id}
|
||||
db.commit()
|
||||
|
||||
return {"status": "stopped", "run_id": run_id}
|
||||
|
||||
Reference in New Issue
Block a user