++
This commit is contained in:
+18
-16
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user