forked from kenzuya/unshackle
fix(serve): defer service hot reload while a remote session uses it
Remote-only serve no longer builds the download queue manager just to read busy services.
This commit is contained in:
@@ -753,7 +753,7 @@ class DownloadQueueManager:
|
||||
|
||||
async def run() -> None:
|
||||
try:
|
||||
applied = await asyncio.to_thread(services.apply_pending, self.busy_services())
|
||||
applied = await asyncio.to_thread(services.apply_pending, busy_services())
|
||||
if applied:
|
||||
log.info(f"Services reloaded after job completion: {', '.join(applied)}")
|
||||
publish_service_event("applied", applied)
|
||||
@@ -1198,3 +1198,14 @@ def get_download_manager() -> DownloadQueueManager:
|
||||
download_manager = DownloadQueueManager(max_concurrent, retention_hours)
|
||||
|
||||
return download_manager
|
||||
|
||||
|
||||
def busy_services() -> set[str]:
|
||||
"""Tags a hot reload must not swap: those with an unfinished job and those a live remote session uses."""
|
||||
from unshackle.core.api.session_store import get_session_store
|
||||
from unshackle.core.api.stats import stats
|
||||
|
||||
busy = {entry.service_tag for entry in get_session_store().list()}
|
||||
if stats.mode != "remote_only":
|
||||
busy |= get_download_manager().busy_services()
|
||||
return busy
|
||||
|
||||
@@ -2734,14 +2734,13 @@ async def clear_temp_handler(request: Optional[web.Request] = None) -> web.Respo
|
||||
|
||||
async def refresh_services_handler(request: Optional[web.Request] = None) -> web.Response:
|
||||
"""Refresh the service repos configured in directories.services and reload the changed services."""
|
||||
from unshackle.core.api.download_manager import get_download_manager
|
||||
from unshackle.core.api.download_manager import busy_services
|
||||
from unshackle.core.api.events import publish_refresh_events
|
||||
from unshackle.core.services import refresh_and_reload
|
||||
|
||||
require_admin(request)
|
||||
try:
|
||||
busy = get_download_manager().busy_services()
|
||||
repos = await asyncio.to_thread(refresh_and_reload, busy)
|
||||
repos = await asyncio.to_thread(refresh_and_reload, busy_services())
|
||||
publish_refresh_events(repos)
|
||||
return web.json_response({"refreshed": all(r["updated"] for r in repos), "repos": repos})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user