add runtime adapters, scheduler, reconciler, and their unit tests
This commit is contained in:
parent
d1976a5fd8
commit
b63d69c81d
10 changed files with 1471 additions and 28 deletions
|
|
@ -153,6 +153,47 @@ class StateDB:
|
|||
self._conn.execute("ROLLBACK")
|
||||
raise
|
||||
|
||||
def update_slot_fields(self, slot_id: str, **fields: object) -> None:
|
||||
"""Update specific slot columns without changing state or last_state_change.
|
||||
|
||||
Uses BEGIN IMMEDIATE. Allowed fields: instance_id, instance_ip,
|
||||
instance_launch_time, lease_count, cooldown_until, interruption_pending.
|
||||
"""
|
||||
allowed = {
|
||||
"instance_id",
|
||||
"instance_ip",
|
||||
"instance_launch_time",
|
||||
"lease_count",
|
||||
"cooldown_until",
|
||||
"interruption_pending",
|
||||
}
|
||||
if not fields:
|
||||
return
|
||||
|
||||
set_parts: list[str] = []
|
||||
params: list[object] = []
|
||||
for k, v in fields.items():
|
||||
if k not in allowed:
|
||||
msg = f"Unknown slot field: {k}"
|
||||
raise ValueError(msg)
|
||||
set_parts.append(f"{k} = ?")
|
||||
params.append(v)
|
||||
|
||||
params.append(slot_id)
|
||||
sql = f"UPDATE slots SET {', '.join(set_parts)} WHERE slot_id = ?"
|
||||
|
||||
self._conn.execute("BEGIN IMMEDIATE")
|
||||
try:
|
||||
self._conn.execute(sql, params)
|
||||
self._record_event_inner(
|
||||
"slot_fields_updated",
|
||||
{"slot_id": slot_id, **fields},
|
||||
)
|
||||
self._conn.execute("COMMIT")
|
||||
except Exception:
|
||||
self._conn.execute("ROLLBACK")
|
||||
raise
|
||||
|
||||
# -- Reservation operations ---------------------------------------------
|
||||
|
||||
def create_reservation(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue