Skip to content

Commit c4aabf4

Browse files
committed
🎨 Refactor socketio handler keys to use web.AppKey for improved clarity and type safety
1 parent b21d32f commit c4aabf4

File tree

1 file changed

+9
-5
lines changed
  • services/web/server/src/simcore_service_webserver/socketio

1 file changed

+9
-5
lines changed

services/web/server/src/simcore_service_webserver/socketio/_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
from collections.abc import Awaitable, Callable
33
from functools import wraps
44
from types import ModuleType
5-
from typing import Any
5+
from typing import Any, Final
66

77
from aiohttp import web
88
from socketio import AsyncServer # type: ignore[import-untyped]
99

10-
APP_CLIENT_SOCKET_DECORATED_HANDLERS_KEY = f"{__name__}.socketio_handlers"
11-
APP_CLIENT_SOCKET_SERVER_KEY = f"{__name__}.socketio_socketio"
10+
APP_CLIENT_SOCKET_DECORATED_HANDLERS_APPKEY: Final = web.AppKey(
11+
"APP_CLIENT_SOCKET_DECORATED_HANDLERS", list[Callable]
12+
)
13+
APP_CLIENT_SOCKET_SERVER_APPKEY: Final = web.AppKey(
14+
"APP_CLIENT_SOCKET_SERVER", AsyncServer
15+
)
1216

1317

1418
def get_socket_server(app: web.Application) -> AsyncServer:
15-
return app[APP_CLIENT_SOCKET_SERVER_KEY]
19+
return app[APP_CLIENT_SOCKET_SERVER_APPKEY]
1620

1721

1822
# The socket ID that was assigned to the client
@@ -76,7 +80,7 @@ def register_socketio_handlers(app: web.Application, module: ModuleType):
7680
partial_fcts = [
7781
_socket_io_handler(app)(func_handler) for func_handler in member_fcts
7882
]
79-
app[APP_CLIENT_SOCKET_DECORATED_HANDLERS_KEY] = partial_fcts
83+
app[APP_CLIENT_SOCKET_DECORATED_HANDLERS_APPKEY] = partial_fcts
8084

8185
# register the fcts
8286
for func in partial_fcts:

0 commit comments

Comments
 (0)