fix: finalize recordings before automatic replay
This commit is contained in:
1 parent
474e56ef8e
commit
a62ac4aef1
25 files changed
+820
-92
No files matched your search
@@ -265,6 +265,9 @@ class DataEngine:
|
||||
session_id = self.current_session_id
|
||||
end_time = time.time()
|
||||
session = self.storage.get_session(session_id)
|
||||
if session and session.end_time is not None and session.status not in ("running", "paused"):
|
||||
logger.debug(f"Session end already published for {session_id}; skipping duplicate")
|
||||
return
|
||||
if session:
|
||||
session.end_time = end_time
|
||||
session.status = status
|
||||
@@ -328,11 +331,55 @@ class DataEngine:
|
||||
start_time=start_time,
|
||||
end_time=end_time or time.time(),
|
||||
local_video_path=str(local_video_path),
|
||||
status="ready",
|
||||
)
|
||||
self.storage.update_video_recording(record)
|
||||
self._publish(
|
||||
"recording_ready",
|
||||
{
|
||||
"session_id": str(self.current_session_id),
|
||||
"video_id": str(video_id),
|
||||
"local_video_path": str(local_video_path),
|
||||
"end_time": record.end_time,
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to record video stop in DataEngine: {e}")
|
||||
|
||||
def record_video_failure(
|
||||
self,
|
||||
video_id: UUID,
|
||||
device_id: str,
|
||||
local_video_path: str | Path | None,
|
||||
start_time: float,
|
||||
error: str,
|
||||
):
|
||||
"""Persist and publish a terminal recording failure."""
|
||||
if not self.storage:
|
||||
return
|
||||
try:
|
||||
record = VideoRecordingRecord(
|
||||
video_id=video_id,
|
||||
session_id=self.current_session_id,
|
||||
device_id=device_id,
|
||||
start_time=start_time,
|
||||
end_time=time.time(),
|
||||
local_video_path=str(local_video_path) if local_video_path else None,
|
||||
status="failed",
|
||||
error=error,
|
||||
)
|
||||
self.storage.update_video_recording(record)
|
||||
self._publish(
|
||||
"recording_failed",
|
||||
{
|
||||
"session_id": str(self.current_session_id),
|
||||
"video_id": str(video_id),
|
||||
"error": error,
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to record video failure in DataEngine: {e}")
|
||||
|
||||
def update_video_path(self, local_video_path: str | Path):
|
||||
"""Update the video path across tables when traces or videos are moved."""
|
||||
if not self.storage or not self.current_session_id:
|
||||
|
||||
@@ -100,3 +100,5 @@ class VideoRecordingRecord(BaseModel):
|
||||
start_time: float
|
||||
end_time: float | None = None
|
||||
local_video_path: str | None = None
|
||||
status: str = "recording"
|
||||
error: str | None = None
|
||||
@@ -213,9 +213,24 @@ class StorageManager:
|
||||
start_time REAL,
|
||||
end_time REAL,
|
||||
local_video_path TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'recording',
|
||||
error TEXT,
|
||||
FOREIGN KEY(session_id) REFERENCES sessions(session_id)
|
||||
)
|
||||
""")
|
||||
video_recording_columns = {
|
||||
row[1] for row in conn.execute("PRAGMA table_info(video_recordings)").fetchall()
|
||||
}
|
||||
if "status" not in video_recording_columns:
|
||||
conn.execute(
|
||||
"ALTER TABLE video_recordings ADD COLUMN status TEXT "
|
||||
"NOT NULL DEFAULT 'recording'"
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE video_recordings SET status = 'ready' WHERE end_time IS NOT NULL"
|
||||
)
|
||||
if "error" not in video_recording_columns:
|
||||
conn.execute("ALTER TABLE video_recordings ADD COLUMN error TEXT")
|
||||
try:
|
||||
conn.execute("ALTER TABLE background_tasks ADD COLUMN logs TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
@@ -273,8 +288,11 @@ class StorageManager:
|
||||
with self._get_connection() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO video_recordings (video_id, session_id, device_id, start_time, end_time, local_video_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO video_recordings (
|
||||
video_id, session_id, device_id, start_time, end_time,
|
||||
local_video_path, status, error
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
str(record.video_id),
|
||||
@@ -283,6 +301,8 @@ class StorageManager:
|
||||
record.start_time,
|
||||
record.end_time,
|
||||
record.local_video_path,
|
||||
record.status,
|
||||
record.error,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
@@ -293,12 +313,14 @@ class StorageManager:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE video_recordings
|
||||
SET end_time = ?, local_video_path = ?
|
||||
SET end_time = ?, local_video_path = ?, status = ?, error = ?
|
||||
WHERE video_id = ?
|
||||
""",
|
||||
(
|
||||
record.end_time,
|
||||
record.local_video_path,
|
||||
record.status,
|
||||
record.error,
|
||||
str(record.video_id),
|
||||
),
|
||||
)
|
||||
@@ -345,6 +367,10 @@ class StorageManager:
|
||||
start_time=row["start_time"],
|
||||
end_time=row["end_time"],
|
||||
local_video_path=row["local_video_path"],
|
||||
status=row["status"] if "status" in row.keys() else (
|
||||
"ready" if row["end_time"] is not None else "recording"
|
||||
),
|
||||
error=row["error"] if "error" in row.keys() else None,
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
Reference in new issue
Block a user