only offload to bg worker when needed.
This commit is contained in:
parent
09c5d7794d
commit
138a497703
3 changed files with 9 additions and 9 deletions
|
|
@ -828,7 +828,7 @@ class DownloadQueue(metaclass=Singleton):
|
||||||
self.done.delete(id)
|
self.done.delete(id)
|
||||||
|
|
||||||
_status: str = "Removed" if removed_files > 0 else "Cleared"
|
_status: str = "Removed" if removed_files > 0 else "Cleared"
|
||||||
self._notify.offload(
|
await self._notify.emit(
|
||||||
Events.CLEARED,
|
Events.CLEARED,
|
||||||
data=item.info,
|
data=item.info,
|
||||||
title=f"Download {_status}",
|
title=f"Download {_status}",
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ async def subscribe(config: Config, notify: EventBus, sio: socketio.AsyncServer,
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not isinstance(data, str) or not data:
|
if not isinstance(data, str) or not data:
|
||||||
notify.offload(
|
await notify.emit(
|
||||||
Events.ERROR,
|
Events.ERROR,
|
||||||
title="Subscription Error",
|
title="Subscription Error",
|
||||||
message="Invalid event type was expecting a string.",
|
message="Invalid event type was expecting a string.",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ LOG: logging.Logger = logging.getLogger(__name__)
|
||||||
@route(RouteType.SOCKET, "cli_post", "socket_cli_post")
|
@route(RouteType.SOCKET, "cli_post", "socket_cli_post")
|
||||||
async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
if not config.console_enabled:
|
if not config.console_enabled:
|
||||||
notify.offload(
|
await notify.emit(
|
||||||
Events.LOG_ERROR,
|
Events.LOG_ERROR,
|
||||||
title="Feature disabled",
|
title="Feature disabled",
|
||||||
message="Console feature is disabled.",
|
message="Console feature is disabled.",
|
||||||
|
|
@ -26,7 +26,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not data:
|
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
|
return
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
@ -93,7 +93,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
assert proc.stdout is not None
|
assert proc.stdout is not None
|
||||||
async for raw_line in proc.stdout:
|
async for raw_line in proc.stdout:
|
||||||
line = raw_line.rstrip(b"\n")
|
line = raw_line.rstrip(b"\n")
|
||||||
notify.offload(
|
await notify.emit(
|
||||||
Events.CLI_OUTPUT,
|
Events.CLI_OUTPUT,
|
||||||
data={"type": "stdout", "line": line.decode("utf-8", errors="replace")},
|
data={"type": "stdout", "line": line.decode("utf-8", errors="replace")},
|
||||||
to=sid,
|
to=sid,
|
||||||
|
|
@ -112,7 +112,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
|
|
||||||
if not chunk:
|
if not chunk:
|
||||||
if buffer:
|
if buffer:
|
||||||
notify.offload(
|
await notify.emit(
|
||||||
Events.CLI_OUTPUT,
|
Events.CLI_OUTPUT,
|
||||||
data={"type": "stdout", "line": buffer.decode("utf-8", errors="replace")},
|
data={"type": "stdout", "line": buffer.decode("utf-8", errors="replace")},
|
||||||
to=sid,
|
to=sid,
|
||||||
|
|
@ -123,7 +123,7 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
*lines, buffer = buffer.split(b"\n")
|
*lines, buffer = buffer.split(b"\n")
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
notify.offload(
|
await notify.emit(
|
||||||
Events.CLI_OUTPUT,
|
Events.CLI_OUTPUT,
|
||||||
data={"type": "stdout", "line": line.decode("utf-8", errors="replace")},
|
data={"type": "stdout", "line": line.decode("utf-8", errors="replace")},
|
||||||
to=sid,
|
to=sid,
|
||||||
|
|
@ -141,6 +141,6 @@ async def cli_post(config: Config, notify: EventBus, sid: str, data: str):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error(f"CLI execute exception was thrown for client '{sid}'.")
|
LOG.error(f"CLI execute exception was thrown for client '{sid}'.")
|
||||||
LOG.exception(e)
|
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:
|
finally:
|
||||||
notify.offload(Events.CLI_CLOSE, data={"exitcode": returncode}, to=sid)
|
await notify.emit(Events.CLI_CLOSE, data={"exitcode": returncode}, to=sid)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue