Skip to content

Commit

Permalink
Test CI failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed May 2, 2024
1 parent 7100c29 commit ec2ee0e
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def exception_logger(exception: Exception, log: Logger) -> bool:

file = self._file_loaders[file_id]
updates_file_path = f".{file_type}:{file_id}.y"
# Test if changes in
# https://github.com/jupyterlab/jupyter-collaboration/pull/299
# broke CI
ystore = self._ystore_class(path=updates_file_path, log=self.log)
self.room = DocumentRoom(
self._room_id,
Expand All @@ -136,7 +139,9 @@ def exception_logger(exception: Exception, log: Logger) -> bool:
try:
await self._websocket_server.start_room(self.room)
except Exception as e:
self.log.error("Room %s failed to start on websocket server", self._room_id)
self.log.error(
"Room %s failed to start on websocket server", self._room_id
)
# Clean room
await self.room.stop()
self.log.info("Room %s deleted", self._room_id)
Expand All @@ -146,7 +151,8 @@ def exception_logger(exception: Exception, log: Logger) -> bool:
_, _, file_id = decode_file_path(self._room_id)
file = self._file_loaders[file_id]
if file.number_of_subscriptions == 0 or (
file.number_of_subscriptions == 1 and self._room_id in file._subscriptions
file.number_of_subscriptions == 1
and self._room_id in file._subscriptions
):
self.log.info("Deleting file %s", file.path)
await self._file_loaders.remove(file_id)
Expand Down Expand Up @@ -242,7 +248,9 @@ async def open(self, room_id):
self.log.error(f"File {file.path} not found.\n{e!r}", exc_info=e)
self.close(1004, f"File {file.path} not found.")
else:
self.log.error(f"Error initializing: {file.path}\n{e!r}", exc_info=e)
self.log.error(
f"Error initializing: {file.path}\n{e!r}", exc_info=e
)
self.close(
1003,
f"Error initializing: {file.path}. You need to close the document.",
Expand Down Expand Up @@ -322,10 +330,14 @@ async def on_message(self, message):
for client in self.room.clients:
if client != self:
task = asyncio.create_task(
client.send(bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data)
client.send(
bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data
)
)
self._websocket_server.background_tasks.add(task)
task.add_done_callback(self._websocket_server.background_tasks.discard)
task.add_done_callback(
self._websocket_server.background_tasks.discard
)

self._message_queue.put_nowait(message)
self._websocket_server.ypatch_nb += 1
Expand All @@ -344,7 +356,9 @@ def on_close(self) -> None:
if self._room_id != "JupyterLab:globalAwareness":
self._emit_awareness_event(self.current_user.username, "leave")

def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = None) -> None:
def _emit(
self, level: LogLevel, action: str | None = None, msg: str | None = None
) -> None:
_, _, file_id = decode_file_path(self._room_id)
path = self._file_id_manager.get_path(file_id)

Expand All @@ -356,12 +370,16 @@ def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = No

self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_EVENTS_URI, data=data)

def _emit_awareness_event(self, username: str, action: str, msg: str | None = None) -> None:
def _emit_awareness_event(
self, username: str, action: str, msg: str | None = None
) -> None:
data = {"roomid": self._room_id, "username": username, "action": action}
if msg:
data["msg"] = msg

self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data)
self.event_logger.emit(
schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data
)

async def _clean_room(self) -> None:
"""
Expand Down

0 comments on commit ec2ee0e

Please sign in to comment.