Skip to content

Commit

Permalink
Remove ws connection after unsubscribe (#547)
Browse files Browse the repository at this point in the history
to allow reconnection
  • Loading branch information
armanddidierjean authored Aug 28, 2024
1 parent 18891cc commit 4078f92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/modules/cdr/endpoints_cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,16 @@ async def create_curriculum_membership(
status_code=403,
detail="You can't remove a curriculum to another user.",
)

wanted_curriculum = await cruds_cdr.get_curriculum_by_id(
db=db,
curriculum_id=curriculum_id,
)
if not wanted_curriculum:
raise HTTPException(
status_code=404,
detail="Invalid curriculum_id",
)
db_user = await get_user_by_id(db=db, user_id=user_id)
if not db_user:
raise HTTPException(
Expand Down Expand Up @@ -1942,7 +1952,7 @@ async def create_curriculum_membership(
message=schemas_cdr.NewUserWSMessageModel(
data=schemas_cdr.CdrUser(
curriculum=schemas_cdr.CurriculumComplete(
**curriculum.__dict__,
**wanted_curriculum.__dict__,
),
**db_user.__dict__,
),
Expand Down
3 changes: 2 additions & 1 deletion app/types/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def _remove_task_from_listening_tasks_callback(
Asyncio task callback to remove the task from the listening_tasks dict
The method is called after the listening task is done or cancelled
"""
self.listening_tasks.pop(room_id)
self.listening_tasks.pop(room_id, None)
self.connections.pop(room_id, None)
hyperion_error_logger.info(
f"Websocket: unsubscribed broadcaster from channel {room_id} for worker {os.getpid()}",
)
Expand Down

0 comments on commit 4078f92

Please sign in to comment.