This commit is contained in:
2026-09-27 23:06:24 +08:00
parent 2d4f9230b1
commit 22450e5bb3
40 changed files with 3040 additions and 697 deletions
+18 -16
View File
@@ -78,22 +78,24 @@ class SimulationStore:
await db.execute(f"UPDATE simulations SET {', '.join(sets)} WHERE id = ?", vals)
await db.commit()
async def sweep_orphan_running_sims(self) -> int:
"""Mark any 'running' simulations as 'interrupted' on startup.
Running simulations live only in the current process — there is no
supervisor that resumes them after a restart. If we don't sweep them,
their status would stay 'running' forever and the report endpoint
would never return a terminal state.
Returns the number of sims swept.
"""
async with aiosqlite.connect(self.global_db_path) as db:
cursor = await db.execute(
"UPDATE simulations SET status = 'interrupted' WHERE status = 'running'"
)
await db.commit()
return cursor.rowcount or 0
async def sweep_orphan_running_sims(self) -> int:
"""Mark any in-flight (non-terminal) simulation as 'interrupted' on
startup. In-flight simulations live only in the current process —
there is no supervisor that resumes them after a restart. If we
don't sweep them, their status would stay stuck in
`generating_world` / `generating_citizens` / `running` / `paused`
forever and the report endpoint would never return a terminal
state.
Returns the number of sims swept.
"""
async with aiosqlite.connect(self.global_db_path) as db:
cursor = await db.execute(
"UPDATE simulations SET status = 'interrupted' "
"WHERE status NOT IN ('completed', 'error', 'cancelled', 'interrupted')"
)
await db.commit()
return cursor.rowcount or 0
async def get_simulation(self, sim_id: str) -> dict | None:
async with aiosqlite.connect(self.global_db_path) as db: