mirror of
https://github.com/rommapp/romm.git
synced 2026-10-12 02:21:58 +00:00
refactor(streaming): drop arguments no caller varies
resolve_owned_session's include_desktop was never passed, and the two teardown helpers and stamp_launched defaulted arguments every caller supplies. The 409 builder's holder snapshot no longer reuses the name of the container above it.
This commit is contained in:
@@ -358,7 +358,7 @@ async def _reserve_container(
|
||||
candidates, request.user.id, platform=platform
|
||||
)
|
||||
if held is not None:
|
||||
holder, _, mine = held
|
||||
own_container, _, mine = held
|
||||
if not session_is_stale(mine):
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
@@ -371,7 +371,7 @@ async def _reserve_container(
|
||||
)
|
||||
# Their own session, abandoned. Take that container back rather than
|
||||
# rolling them onto a free one and stranding this one until its TTL.
|
||||
candidates = [holder]
|
||||
candidates = [own_container]
|
||||
|
||||
async def try_claim(candidate: ResolvedContainer) -> bool:
|
||||
# SET NX is atomic: exactly one concurrent claim wins the key. The TTL
|
||||
@@ -441,7 +441,7 @@ async def _reserve_container(
|
||||
# has to come from a live session or the message names no one.
|
||||
snapshots = [await get_session(candidate.key) or {} for candidate in candidates]
|
||||
draining = any(snapshot.get("draining") for snapshot in snapshots)
|
||||
existing = next(
|
||||
holder = next(
|
||||
(
|
||||
snapshot
|
||||
for snapshot in snapshots
|
||||
@@ -460,8 +460,8 @@ async def _reserve_container(
|
||||
detail={
|
||||
"message": message,
|
||||
"draining": draining,
|
||||
"rom_name": access.visible_rom_name(request, existing),
|
||||
"claimed_at": existing.get("claimed_at"),
|
||||
"rom_name": access.visible_rom_name(request, holder),
|
||||
"claimed_at": holder.get("claimed_at"),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ async def resolve_named_container(
|
||||
|
||||
|
||||
async def resolve_owned_session(
|
||||
platform: str, request: Request, *, include_desktop: bool = False
|
||||
platform: str, request: Request
|
||||
) -> tuple[ResolvedContainer, str, dict[str, Any]]:
|
||||
"""Find the caller's session for this platform in its first pool.
|
||||
|
||||
@@ -194,7 +194,8 @@ async def resolve_owned_session(
|
||||
session = await get_live_session(session_key)
|
||||
if session is None:
|
||||
continue
|
||||
if not _session_in_scope(session, platform, include_desktop):
|
||||
# These routes act on a game; a desktop is reached by naming it.
|
||||
if not _session_in_scope(session, platform, include_desktop=False):
|
||||
continue
|
||||
if session.get("user_id") == request.user.id:
|
||||
return candidate, session_key, session
|
||||
|
||||
@@ -396,7 +396,7 @@ async def _teardown_abandoned_session(
|
||||
session_key: str,
|
||||
session: dict[str, Any],
|
||||
*,
|
||||
claimed_by: int | None = None,
|
||||
claimed_by: int,
|
||||
) -> bool:
|
||||
"""Free a container whose owner vanished without releasing (heartbeat went
|
||||
stale). Same order as an owner release: stop the emulator so the card is
|
||||
@@ -470,7 +470,7 @@ async def await_teardown_within_budget(
|
||||
session: dict[str, Any],
|
||||
budget: float,
|
||||
*,
|
||||
claimed_by: int | None = None,
|
||||
claimed_by: int,
|
||||
) -> bool:
|
||||
"""Tear down an abandoned session, but only wait `budget` seconds for it.
|
||||
|
||||
|
||||
@@ -426,7 +426,7 @@ async def hold_session_claim(session_key: str, claim: dict[str, Any]) -> None:
|
||||
|
||||
|
||||
async def stamp_launched(
|
||||
session_key: str, claim: dict[str, Any], host: str | None = None
|
||||
session_key: str, claim: dict[str, Any], host: str | None
|
||||
) -> None:
|
||||
"""Record that the activate returned, so the status poll stops asking the
|
||||
broker for an extraction phase.
|
||||
|
||||
Reference in New Issue
Block a user