project/kovalenko-SCRUM-110-database-holes-visibility #34
@@ -60,19 +60,23 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
|
|||||||
# receive forever
|
# receive forever
|
||||||
while True:
|
while True:
|
||||||
data = await websocket.receive_text()
|
data = await websocket.receive_text()
|
||||||
if (data):
|
try:
|
||||||
ws_data = WebSocketData.model_validate(json.loads(data))
|
if (data):
|
||||||
session = SessionLocal()
|
ws_data = WebSocketData.model_validate(json.loads(data))
|
||||||
update_query = (
|
session = SessionLocal()
|
||||||
processed_agent_data.update()
|
update_query = (
|
||||||
.where(processed_agent_data.c.id == ws_data.id)
|
processed_agent_data.update()
|
||||||
.values(visible=False)
|
.where(processed_agent_data.c.id == ws_data.id)
|
||||||
).returning(processed_agent_data)
|
.values(visible=False)
|
||||||
res = session.execute(update_query).fetchone()
|
).returning(processed_agent_data)
|
||||||
if (not res):
|
res = session.execute(update_query).fetchone()
|
||||||
print("Websocket update fail")
|
if (not res):
|
||||||
session.commit()
|
session.rollback()
|
||||||
session.close()
|
raise Exception("Error while websocket PUT")
|
||||||
|
session.commit()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
|
|
||||||
except WebSocketDisconnect:
|
except WebSocketDisconnect:
|
||||||
subscriptions.remove(websocket)
|
subscriptions.remove(websocket)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user