Skip to content

Commit ff1856b

Browse files
committed
Removed apparently unused endpoints and functions from websocket router
1 parent d3effca commit ff1856b

File tree

2 files changed

+2
-71
lines changed

2 files changed

+2
-71
lines changed

src/murfey/server/api/websocket.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import asyncio
43
import json
54
import logging
65
from datetime import datetime
@@ -9,7 +8,6 @@
98
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
109
from sqlmodel import Session, select
1110

12-
import murfey.server.prometheus as prom
1311
from murfey.server.murfey_db import get_murfey_db_session
1412
from murfey.util import sanitise
1513
from murfey.util.db import ClientEnvironment
@@ -69,31 +67,6 @@ async def broadcast(self, message: str):
6967
manager = ConnectionManager()
7068

7169

72-
@ws.websocket("/test/{client_id}")
73-
async def websocket_endpoint(websocket: WebSocket, client_id: int):
74-
await manager.connect(websocket, client_id)
75-
await manager.broadcast(f"Client {client_id} joined")
76-
try:
77-
while True:
78-
data = await websocket.receive_text()
79-
try:
80-
json_data: dict = json.loads(data)
81-
if json_data["type"] == "log": # and isinstance(json_data, dict)
82-
json_data.pop("type")
83-
await forward_log(json_data, websocket)
84-
except Exception:
85-
await manager.broadcast(f"Client #{client_id} sent message {data}")
86-
except WebSocketDisconnect:
87-
log.info(f"Disconnecting Client {int(sanitise(str(client_id)))}")
88-
murfey_db = next(get_murfey_db_session())
89-
client_env = murfey_db.exec(
90-
select(ClientEnvironment).where(ClientEnvironment.client_id == client_id)
91-
).one()
92-
prom.monitoring_switch.labels(visit=client_env.visit).set(0)
93-
manager.disconnect(client_id)
94-
await manager.broadcast(f"Client #{client_id} disconnected")
95-
96-
9770
@ws.websocket("/connect/{client_id}")
9871
async def websocket_connection_endpoint(
9972
websocket: WebSocket,
@@ -120,17 +93,6 @@ async def websocket_connection_endpoint(
12093
await manager.broadcast(f"Client #{client_id} disconnected")
12194

12295

123-
async def check_connections(active_connections: list[WebSocket]):
124-
log.info("Checking connections")
125-
for connection in active_connections:
126-
log.info("Checking response")
127-
try:
128-
await asyncio.wait_for(connection.receive(), timeout=10)
129-
except asyncio.TimeoutError:
130-
log.info(f"Disconnecting Client {connection[0]}")
131-
manager.disconnect(connection[0], connection[1])
132-
133-
13496
async def forward_log(logrecord: dict[str, Any], websocket: WebSocket):
13597
record_name = logrecord["name"]
13698
logrecord.pop("msecs", None)
@@ -142,26 +104,8 @@ async def forward_log(logrecord: dict[str, Any], websocket: WebSocket):
142104
logging.getLogger(record_name).handle(logging.makeLogRecord(logrecord))
143105

144106

145-
@ws.delete("/test/{client_id}")
146-
async def close_ws_connection(client_id: int):
147-
murfey_db: Session = next(get_murfey_db_session())
148-
client_env = murfey_db.exec(
149-
select(ClientEnvironment).where(ClientEnvironment.client_id == client_id)
150-
).one()
151-
client_env.connected = False
152-
visit_name = client_env.visit
153-
murfey_db.add(client_env)
154-
murfey_db.commit()
155-
murfey_db.close()
156-
client_id_str = str(client_id).replace("\r\n", "").replace("\n", "")
157-
log.info(f"Disconnecting {client_id_str}")
158-
manager.disconnect(client_id)
159-
prom.monitoring_switch.labels(visit=visit_name).set(0)
160-
await manager.broadcast(f"Client #{client_id} disconnected")
161-
162-
163107
@ws.delete("/connect/{client_id}")
164-
async def close_unrecorded_ws_connection(client_id: int | str):
108+
async def close_websocket_connection(client_id: int | str):
165109
client_id_str = str(client_id).replace("\r\n", "").replace("\n", "")
166110
log.info(f"Disconnecting {client_id_str}")
167111
manager.disconnect(client_id)

src/murfey/util/route_manifest.yaml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,27 +1255,14 @@ murfey.server.api.session_info.tomo_router:
12551255
methods:
12561256
- GET
12571257
murfey.server.api.websocket.ws:
1258-
- path: /ws/test/{client_id}
1259-
function: websocket_endpoint
1260-
path_params:
1261-
- name: client_id
1262-
type: int
1263-
methods: []
12641258
- path: /ws/connect/{client_id}
12651259
function: websocket_connection_endpoint
12661260
path_params:
12671261
- name: client_id
12681262
type: int | str
12691263
methods: []
1270-
- path: /ws/test/{client_id}
1271-
function: close_ws_connection
1272-
path_params:
1273-
- name: client_id
1274-
type: int
1275-
methods:
1276-
- DELETE
12771264
- path: /ws/connect/{client_id}
1278-
function: close_unrecorded_ws_connection
1265+
function: close_websocket_connection
12791266
path_params:
12801267
- name: client_id
12811268
type: int | str

0 commit comments

Comments
 (0)