mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Teaches the streaming endpoints the webstation activate/exit contract alongside the existing per-emulator broker mods, lets one container serve a pool of platforms, and claims the first free container from that pool. Sessions now sync save states, save archives and whole memory cards back into the RomM library on release, keep every capture as browsable history, and record the disc a state was taken on so a resume remounts it. Container adoptions track a card the container already held so it is never wiped without asking.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from sqlalchemy import select
|
|
from sqlalchemy.exc import IntegrityError
|
|
from sqlalchemy.orm import Session
|
|
|
|
from decorators.database import begin_session
|
|
from models.container_adoption import AdoptionOutcome, StreamingContainerAdoption
|
|
|
|
from .base_handler import DBBaseHandler
|
|
|
|
|
|
class DBContainerAdoptionsHandler(DBBaseHandler):
|
|
@begin_session
|
|
def get_adoption(
|
|
self,
|
|
container_key: str,
|
|
session: Session = None, # type: ignore
|
|
) -> StreamingContainerAdoption | None:
|
|
return session.scalar(
|
|
select(StreamingContainerAdoption).filter_by(container_key=container_key)
|
|
)
|
|
|
|
@begin_session
|
|
def add_adoption(
|
|
self,
|
|
container_key: str,
|
|
outcome: AdoptionOutcome,
|
|
user_id: int,
|
|
session: Session = None, # type: ignore
|
|
) -> StreamingContainerAdoption | None:
|
|
"""Returns None when another claim recorded the decision first. The
|
|
unique constraint is the arbiter, not the earlier read."""
|
|
adoption = StreamingContainerAdoption(
|
|
container_key=container_key,
|
|
outcome=outcome,
|
|
decided_by_user_id=user_id,
|
|
)
|
|
try:
|
|
session.add(adoption)
|
|
session.flush()
|
|
except IntegrityError:
|
|
session.rollback()
|
|
return None
|
|
return adoption
|