diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index dd579c0aa..d4726ecd2 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -1109,7 +1109,7 @@ def session_exists(project_id, session_id): return row is not None -def check_recording_status(project_id: int) -> bool: +def check_recording_status(project_id: int) -> dict: query = f""" WITH project_sessions AS ( SELECT * FROM public.sessions WHERE project_id = %(project_id)s @@ -1124,7 +1124,9 @@ def check_recording_status(project_id: int) -> bool: (SELECT COUNT(*) FROM sessions_with_duration) = 0 THEN 1 WHEN (SELECT COUNT(*) FROM project_sessions) > 0 AND (SELECT COUNT(*) FROM sessions_with_duration) > 0 THEN 2 - END AS recording_status; + END AS recording_status, + COUNT(*) AS sessions_count + FROM project_sessions; """ with pg_client.PostgresClient() as cur: @@ -1132,5 +1134,9 @@ def check_recording_status(project_id: int) -> bool: cur.execute(query) row = cur.fetchone() - return row["recording_status"] + return { + "recording_status": row["recording_status"], + "sessions_count": row["sessions_count"] + } + diff --git a/api/routers/core.py b/api/routers/core.py index a8904db66..14d17b4c2 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -844,6 +844,23 @@ async def delete_msteams_integration(webhookId: int, _=Body(None), @app.get('/{project_id}/check-recording-status', tags=["sessions"]) async def check_recording_status(project_id: int): + """ + Check the recording status and sessions count for a given project ID. + + Args: + project_id (int): The ID of the project to check. + + Returns: + dict: A dictionary containing the recording status and sessions count. + The dictionary has the following structure: + { + "recording_status": int, # The recording status: + # 0 - No sessions + # 1 - Processing + # 2 - Ready + "sessions_count": int # The total count of sessions + } + """ return {"data": sessions.check_recording_status(project_id=project_id)}