From d76abe019f8068e5a7731cecfd8e275ee3a96e5d Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 8 Jul 2021 07:50:08 -0400 Subject: [PATCH] update_manager: return True when on update success All calls to update now return a boolean value. When performing a full upate this return value is used to check if Moonraker should wait for Klippy to reconnect. Signed-off-by: Eric Callahan --- .../components/update_manager/base_deploy.py | 4 +- .../components/update_manager/git_deploy.py | 5 ++- .../update_manager/update_manager.py | 42 ++++++++++--------- .../components/update_manager/zip_deploy.py | 5 ++- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/moonraker/components/update_manager/base_deploy.py b/moonraker/components/update_manager/base_deploy.py index 1ca993d..d98ad32 100644 --- a/moonraker/components/update_manager/base_deploy.py +++ b/moonraker/components/update_manager/base_deploy.py @@ -32,8 +32,8 @@ class BaseDeploy: async def refresh(self) -> None: pass - async def update(self) -> None: - pass + async def update(self) -> bool: + return False def get_update_status(self) -> Dict[str, Any]: return {} diff --git a/moonraker/components/update_manager/git_deploy.py b/moonraker/components/update_manager/git_deploy.py index 32d6159..f482365 100644 --- a/moonraker/components/update_manager/git_deploy.py +++ b/moonraker/components/update_manager/git_deploy.py @@ -77,7 +77,7 @@ class GitDeploy(AppDeploy): self._is_valid = True self.log_info("Validity check for git repo passed") - async def update(self) -> None: + async def update(self) -> bool: await self.repo.wait_for_init() if not self._is_valid: raise self.log_exc("Update aborted, repo not valid", False) @@ -86,7 +86,7 @@ class GitDeploy(AppDeploy): "Update aborted, repo has been modified", False) if self.repo.is_current(): # No need to update - return + return False self.cmd_helper.notify_update_response( f"Updating Application {self.name}...") inst_hash = await self._get_file_hash(self.install_script) @@ -99,6 +99,7 @@ class GitDeploy(AppDeploy): await self._update_repo_state(need_fetch=False) await self.restart_service() self.notify_status("Update Finished...", is_complete=True) + return True async def recover(self, hard: bool = False, diff --git a/moonraker/components/update_manager/update_manager.py b/moonraker/components/update_manager/update_manager.py index a6c9f5d..0bea44c 100644 --- a/moonraker/components/update_manager/update_manager.py +++ b/moonraker/components/update_manager/update_manager.py @@ -315,21 +315,23 @@ class UpdateManager: kupdater = self.updaters.get('klipper') if isinstance(kupdater, AppDeploy): self.klippy_identified_evt = asyncio.Event() + klippy_updated = True if not await self._check_need_reinstall(app_name): - await kupdater.update() - self.cmd_helper.notify_update_response( - "Waiting for Klippy to reconnect (this may take" - " up to 2 minutes)...") - try: - await asyncio.wait_for( - self.klippy_identified_evt.wait(), 120.) - except asyncio.TimeoutError: + klippy_updated = await kupdater.update() + if klippy_updated: self.cmd_helper.notify_update_response( - "Klippy reconnect timed out...") - else: - self.cmd_helper.notify_update_response( - f"Klippy Reconnected") - self.klippy_identified_evt = None + "Waiting for Klippy to reconnect (this may take" + " up to 2 minutes)...") + try: + await asyncio.wait_for( + self.klippy_identified_evt.wait(), 120.) + except asyncio.TimeoutError: + self.cmd_helper.notify_update_response( + "Klippy reconnect timed out...") + else: + self.cmd_helper.notify_update_response( + f"Klippy Reconnected") + self.klippy_identified_evt = None # Update Moonraker app_name = 'moonraker' @@ -817,10 +819,10 @@ class PackageDeploy(BaseDeploy): self.refresh_evt.set() self.refresh_evt = None - async def update(self) -> None: + async def update(self) -> bool: async with self.mutex: if not self.available_packages: - return + return False self.cmd_helper.notify_update_response("Updating packages...") try: await self._update_apt(force=True, notify=True) @@ -832,6 +834,7 @@ class PackageDeploy(BaseDeploy): self.available_packages = [] self.cmd_helper.notify_update_response( "Package update finished...", is_complete=True) + return True async def _update_apt(self, force: bool = False, @@ -936,22 +939,22 @@ class WebClientDeploy(BaseDeploy): f"size: {size}\n" f"Content Type: {content_type}") - async def update(self) -> None: + async def update(self) -> bool: async with self.mutex: if self.remote_version == "?": await self._get_remote_version() if self.remote_version == "?": raise self.server.error( f"Client {self.repo}: Unable to locate update") - self.cmd_helper.notify_update_response( - f"Updating Web Client {self.name}...") dl_url, content_type, size = self.dl_info if dl_url == "?": raise self.server.error( f"Client {self.repo}: Invalid download url") if self.version == self.remote_version: # Already up to date - return + return False + self.cmd_helper.notify_update_response( + f"Updating Web Client {self.name}...") self.cmd_helper.notify_update_response( f"Downloading Client: {self.name}") with tempfile.TemporaryDirectory( @@ -975,6 +978,7 @@ class WebClientDeploy(BaseDeploy): tpe, version_path.write_text, self.version) self.cmd_helper.notify_update_response( f"Client Update Finished: {self.name}", is_complete=True) + return True def _extract_release(self, persist_dir: pathlib.Path, diff --git a/moonraker/components/update_manager/zip_deploy.py b/moonraker/components/update_manager/zip_deploy.py index 25c523d..781d52e 100644 --- a/moonraker/components/update_manager/zip_deploy.py +++ b/moonraker/components/update_manager/zip_deploy.py @@ -339,13 +339,13 @@ class ZipDeploy(AppDeploy): with zipfile.ZipFile(release_zip) as zf: zf.extractall(self.path) - async def update(self, force_dep_update: bool = False) -> None: + async def update(self, force_dep_update: bool = False) -> bool: async with self.mutex: if not self._is_valid: raise self.log_exc("Update aborted, repo not valid", False) if self.short_version == self.latest_version: # already up to date - return + return False self.cmd_helper.notify_update_response( f"Updating Application {self.name}...") npm_hash = await self._get_file_hash(self.npm_pkg_json) @@ -366,6 +366,7 @@ class ZipDeploy(AppDeploy): await self._update_repo_state() await self.restart_service() self.notify_status("Update Finished...", is_complete=True) + return True async def recover(self, hard: bool = False,