refactor(gateway/hosted_rooms): inline replica clock helper, collapse driver literal

This commit is contained in:
Teknium
2026-09-02 16:23:44 -07:00
parent 44e37bc7e3
commit c4bc0ada79
2 changed files with 4 additions and 10 deletions
+1 -3
View File
@@ -22,9 +22,7 @@ from gateway.hosted_rooms_common import (
)
Clock = Callable[[], float]
TaskStatus = Literal[
"queued", "running", "settled", "failed", "cancelled", "indeterminate", "deferred", "stopping",
]
TaskStatus = Literal["queued", "running", "settled", "failed", "cancelled", "indeterminate", "deferred", "stopping"]
TerminalStatus = Literal["settled", "failed"]
MAX_IDENTIFIER_CHARS = 128
+3 -7
View File
@@ -105,10 +105,6 @@ def _positive_int(value: Any, message: str) -> int:
return positive_int(value, error=ReplicaError, message=message)
def _clock(now: float | None) -> float:
return time.time() if now is None else float(now)
def _control_event_json(payload: dict[str, Any]) -> tuple[str, str]:
"""Canonical (actor_json, payload_json) for a system authority-control event."""
return (
@@ -168,7 +164,7 @@ def ingest_page(
room_name = _validate_room_name(room_name)
_, members_json = _validate_members(members)
events, authority = _validate_page(page)
now = _clock(now)
now = time.time() if now is None else float(now)
with _replica_transaction(db_path) as conn:
row = conn.execute(
@@ -274,7 +270,7 @@ def promote_replica(
room_id = _room_id(room_id)
if not isinstance(reason, str) or not reason or len(reason) > 200:
raise ReplicaError("reason must be a non-empty string of at most 200 chars")
now = _clock(now)
now = time.time() if now is None else float(now)
local_gateway = local_authority_gateway_id()
with _replica_transaction(db_path) as conn:
@@ -353,7 +349,7 @@ def demote_room(
observed_gateway_id, label="observed_gateway_id", max_chars=MAX_ACTOR_ID_CHARS
)
observed_epoch = _positive_int(observed_epoch, "observed_epoch must be a positive integer")
now = _clock(now)
now = time.time() if now is None else float(now)
local_gateway = local_authority_gateway_id()
with _transaction(db_path, immediate=True) as conn: