Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid restarting backend if no deps installed #2650

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions backend/src/dependencies/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def install_dependencies_sync(
):
dependencies_to_install = get_deps_to_install(dependencies)
if len(dependencies_to_install) == 0:
return
return 0

extra_index_urls = {
dep_info.extra_index_url
Expand Down Expand Up @@ -104,6 +104,8 @@ def install_dependencies_sync(
for dep_info in dependencies_to_install:
installed_packages[dep_info.package_name] = dep_info.version

return len(dependencies_to_install)


async def install_dependencies(
dependencies: list[DependencyInfo],
Expand All @@ -112,12 +114,11 @@ async def install_dependencies(
):
# If there's no progress callback, just install the dependencies synchronously
if update_progress_cb is None:
install_dependencies_sync(dependencies)
return
return install_dependencies_sync(dependencies)

dependencies_to_install = get_deps_to_install(dependencies)
if len(dependencies_to_install) == 0:
return
return 0

dependency_name_map = {
dep_info.package_name: dep_info.display_name or dep_info.package_name
Expand Down Expand Up @@ -227,6 +228,8 @@ def get_progress_amount():
for dep_info in dependencies_to_install:
installed_packages[dep_info.package_name] = dep_info.version

return len(dependencies_to_install)


__all__ = [
"DependencyInfo",
Expand Down
17 changes: 9 additions & 8 deletions backend/src/server_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ async def install_deps(dependencies: list[api.Dependency]):
)
for dep in dependencies
]
await install_dependencies(dep_info, update_progress_cb, logger)
num_installed = await install_dependencies(dep_info, update_progress_cb, logger)
return num_installed

packages = await worker.get_packages()

Expand All @@ -217,10 +218,10 @@ async def install_deps(dependencies: list[api.Dependency]):
if dep.auto_update and is_installed:
to_install.append(dep)

if len(to_install) > 0:
try:
await install_deps(to_install)
try:
num_installed = await install_deps(to_install)

if num_installed > 0:
flags = []
if config.error_on_failed_node:
flags.append("--error-on-failed-node")
Expand All @@ -229,10 +230,10 @@ async def install_deps(dependencies: list[api.Dependency]):
flags.append("--close-after-start")

await worker.restart(flags)
except Exception as ex:
logger.error(f"Error installing dependencies: {ex}", exc_info=True)
if config.close_after_start:
raise ValueError("Error installing dependencies") from ex
except Exception as ex:
logger.error(f"Error installing dependencies: {ex}", exc_info=True)
if config.close_after_start:
raise ValueError("Error installing dependencies") from ex

logger.info("Done checking dependencies...")

Expand Down
Loading