From 138a497703ce230fc5685696e5826587a4169539 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 18 Jul 2025 21:14:42 +0300 Subject: [PATCH] only offload to bg worker when needed. --- app/library/DownloadQueue.py | 2 +- app/routes/socket/connection.py | 2 +- app/routes/socket/terminal.py | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/library/DownloadQueue.py b/app/library/DownloadQueue.py index 90b6e6aa..900c1e25 100644 --- a/app/library/DownloadQueue.py +++ b/app/library/DownloadQueue.py @@ -828,7 +828,7 @@ class DownloadQueue(metaclass=Singleton): self.done.delete(id) _status: str = "Removed" if removed_files > 0 else "Cleared" - self._notify.offload( + await self._notify.emit( Events.CLEARED, data=item.info, title=f"Download {_status}", diff --git a/app/routes/socket/connection.py b/app/routes/socket/connection.py index f751bfef..bb2d0b7f 100644 --- a/app/routes/socket/connection.py +++ b/app/routes/socket/connection.py @@ -66,7 +66,7 @@ async def subscribe(config: Config, notify: EventBus, sio: socketio.AsyncServer, """ if not isinstance(data, str) or not data: - notify.offload( + await notify.emit( Events.ERROR, title="Subscription Error", message="Invalid event type was expecting a string.", diff --git a/app/routes/socket/terminal.py b/app/routes/socket/terminal.py index 5fe143ff..affc0cbe 100644 --- a/app/routes/socket/terminal.py +++ b/app/routes/socket/terminal.py @@ -17,7 +17,7 @@ LOG: logging.Logger = logging.getLogger(__name__) @route(RouteType.SOCKET, "cli_post", "socket_cli_post") async def cli_post(config: Config, notify: EventBus, sid: str, data: str): if not config.console_enabled: - notify.offload( + await notify.emit( Events.LOG_ERROR, title="Feature disabled", message="Console feature is disabled.", @@ -26,7 +26,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str): return if not data: - notify.offload(Events.CLI_CLOSE, data={"exitcode": 0}, to=sid) + await notify.emit(Events.CLI_CLOSE, data={"exitcode": 0}, to=sid) return import asyncio @@ -93,7 +93,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str): assert proc.stdout is not None async for raw_line in proc.stdout: line = raw_line.rstrip(b"\n") - notify.offload( + await notify.emit( Events.CLI_OUTPUT, data={"type": "stdout", "line": line.decode("utf-8", errors="replace")}, to=sid, @@ -112,7 +112,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str): if not chunk: if buffer: - notify.offload( + await notify.emit( Events.CLI_OUTPUT, data={"type": "stdout", "line": buffer.decode("utf-8", errors="replace")}, to=sid, @@ -123,7 +123,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str): *lines, buffer = buffer.split(b"\n") for line in lines: - notify.offload( + await notify.emit( Events.CLI_OUTPUT, data={"type": "stdout", "line": line.decode("utf-8", errors="replace")}, to=sid, @@ -141,6 +141,6 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str): except Exception as e: LOG.error(f"CLI execute exception was thrown for client '{sid}'.") LOG.exception(e) - notify.offload(Events.CLI_OUTPUT, data={"type": "stderr", "line": str(e)}, to=sid) + await notify.emit(Events.CLI_OUTPUT, data={"type": "stderr", "line": str(e)}, to=sid) finally: - notify.offload(Events.CLI_CLOSE, data={"exitcode": returncode}, to=sid) + await notify.emit(Events.CLI_CLOSE, data={"exitcode": returncode}, to=sid)