55from app .core .database_context import Collection , Database
66from app .core .logging import logger
77from app .domain .admin .replay_updates import ReplaySessionUpdate
8+ from app .domain .enums .replay import ReplayStatus
89from app .domain .events .event_models import CollectionNames
910from app .domain .replay import ReplayFilter , ReplaySessionState
1011from app .infrastructure .mappers import ReplayStateMapper
@@ -42,13 +43,13 @@ async def get_session(self, session_id: str) -> ReplaySessionState | None:
4243 return self ._mapper .from_mongo_document (data ) if data else None
4344
4445 async def list_sessions (
45- self , status : str | None = None , user_id : str | None = None , limit : int = 100 , skip : int = 0
46+ self , status : ReplayStatus | None = None , user_id : str | None = None , limit : int = 100 , skip : int = 0
4647 ) -> list [ReplaySessionState ]:
4748 collection = self .replay_collection
4849
49- query = {}
50+ query : dict [ str , object ] = {}
5051 if status :
51- query ["status" ] = status
52+ query ["status" ] = status . value
5253 if user_id :
5354 query ["config.filter.user_id" ] = user_id
5455
@@ -58,15 +59,20 @@ async def list_sessions(
5859 sessions .append (self ._mapper .from_mongo_document (doc ))
5960 return sessions
6061
61- async def update_session_status (self , session_id : str , status : str ) -> bool :
62+ async def update_session_status (self , session_id : str , status : ReplayStatus ) -> bool :
6263 """Update the status of a replay session"""
63- result = await self .replay_collection .update_one ({"session_id" : session_id }, {"$set" : {"status" : status }})
64+ result = await self .replay_collection .update_one ({"session_id" : session_id }, {"$set" : {"status" : status . value }})
6465 return result .modified_count > 0
6566
6667 async def delete_old_sessions (self , cutoff_time : str ) -> int :
6768 """Delete old completed/failed/cancelled sessions"""
69+ terminal_statuses = [
70+ ReplayStatus .COMPLETED .value ,
71+ ReplayStatus .FAILED .value ,
72+ ReplayStatus .CANCELLED .value ,
73+ ]
6874 result = await self .replay_collection .delete_many (
69- {"created_at" : {"$lt" : cutoff_time }, "status" : {"$in" : [ "completed" , "failed" , "cancelled" ] }}
75+ {"created_at" : {"$lt" : cutoff_time }, "status" : {"$in" : terminal_statuses }}
7076 )
7177 return result .deleted_count
7278
0 commit comments