diff --git a/src/application/service/device/connection_manager.py b/src/application/service/device/connection_manager.py index 234e3a5..2526c3e 100644 --- a/src/application/service/device/connection_manager.py +++ b/src/application/service/device/connection_manager.py @@ -6,6 +6,9 @@ class ConnectionManager: + """ + Connection Manager is responsible to manage and store reference of device's connection + """ PREFIX_KEY_DEVICE = "device_connected:" @@ -21,15 +24,30 @@ def __init__(self, cache: Cache, application_instance_name: str) -> None: self.local_device_store = dict() async def register_application(self) -> None: + """ + Register the Application + """ + # TODO : Put the Instance Name to Redis pass async def unregister_application(self) -> None: + """ + Unregister the Application + """ + # TODO : Remove the Instance Name from Redis + # TODO : How manage the crash of application ? (liveness probing) pass def _get_device_key(self, device_id: str): + """ + Format Device Key for Redis + """ return f"{self.PREFIX_KEY_DEVICE}{device_id}" async def register_connection(self, websocket: WebSocket, device_id: str): + """ + Register Connection for Device Connected to this specific instance + """ async with self.cache.acquire() as _cache_connection: await _cache_connection.set( key=self._get_device_key(device_id=device_id), @@ -38,6 +56,9 @@ async def register_connection(self, websocket: WebSocket, device_id: str): self.local_device_store[device_id] = websocket async def unregister_connection(self, websocket: WebSocket, device_id: str): + """ + Unregister Connection for Device Connected to this specific instance + """ if self.local_device_store.get(device_id, None) is not None: del self.local_device_store[device_id] async with self.cache.acquire() as _cache_connection: