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 <arksine.code@gmail.com>
This commit is contained in:
parent
b6cd19d6ef
commit
d76abe019f
|
@ -32,8 +32,8 @@ class BaseDeploy:
|
||||||
async def refresh(self) -> None:
|
async def refresh(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def update(self) -> None:
|
async def update(self) -> bool:
|
||||||
pass
|
return False
|
||||||
|
|
||||||
def get_update_status(self) -> Dict[str, Any]:
|
def get_update_status(self) -> Dict[str, Any]:
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -77,7 +77,7 @@ class GitDeploy(AppDeploy):
|
||||||
self._is_valid = True
|
self._is_valid = True
|
||||||
self.log_info("Validity check for git repo passed")
|
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()
|
await self.repo.wait_for_init()
|
||||||
if not self._is_valid:
|
if not self._is_valid:
|
||||||
raise self.log_exc("Update aborted, repo not valid", False)
|
raise self.log_exc("Update aborted, repo not valid", False)
|
||||||
|
@ -86,7 +86,7 @@ class GitDeploy(AppDeploy):
|
||||||
"Update aborted, repo has been modified", False)
|
"Update aborted, repo has been modified", False)
|
||||||
if self.repo.is_current():
|
if self.repo.is_current():
|
||||||
# No need to update
|
# No need to update
|
||||||
return
|
return False
|
||||||
self.cmd_helper.notify_update_response(
|
self.cmd_helper.notify_update_response(
|
||||||
f"Updating Application {self.name}...")
|
f"Updating Application {self.name}...")
|
||||||
inst_hash = await self._get_file_hash(self.install_script)
|
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._update_repo_state(need_fetch=False)
|
||||||
await self.restart_service()
|
await self.restart_service()
|
||||||
self.notify_status("Update Finished...", is_complete=True)
|
self.notify_status("Update Finished...", is_complete=True)
|
||||||
|
return True
|
||||||
|
|
||||||
async def recover(self,
|
async def recover(self,
|
||||||
hard: bool = False,
|
hard: bool = False,
|
||||||
|
|
|
@ -315,21 +315,23 @@ class UpdateManager:
|
||||||
kupdater = self.updaters.get('klipper')
|
kupdater = self.updaters.get('klipper')
|
||||||
if isinstance(kupdater, AppDeploy):
|
if isinstance(kupdater, AppDeploy):
|
||||||
self.klippy_identified_evt = asyncio.Event()
|
self.klippy_identified_evt = asyncio.Event()
|
||||||
|
klippy_updated = True
|
||||||
if not await self._check_need_reinstall(app_name):
|
if not await self._check_need_reinstall(app_name):
|
||||||
await kupdater.update()
|
klippy_updated = await kupdater.update()
|
||||||
self.cmd_helper.notify_update_response(
|
if klippy_updated:
|
||||||
"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(
|
self.cmd_helper.notify_update_response(
|
||||||
"Klippy reconnect timed out...")
|
"Waiting for Klippy to reconnect (this may take"
|
||||||
else:
|
" up to 2 minutes)...")
|
||||||
self.cmd_helper.notify_update_response(
|
try:
|
||||||
f"Klippy Reconnected")
|
await asyncio.wait_for(
|
||||||
self.klippy_identified_evt = None
|
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
|
# Update Moonraker
|
||||||
app_name = 'moonraker'
|
app_name = 'moonraker'
|
||||||
|
@ -817,10 +819,10 @@ class PackageDeploy(BaseDeploy):
|
||||||
self.refresh_evt.set()
|
self.refresh_evt.set()
|
||||||
self.refresh_evt = None
|
self.refresh_evt = None
|
||||||
|
|
||||||
async def update(self) -> None:
|
async def update(self) -> bool:
|
||||||
async with self.mutex:
|
async with self.mutex:
|
||||||
if not self.available_packages:
|
if not self.available_packages:
|
||||||
return
|
return False
|
||||||
self.cmd_helper.notify_update_response("Updating packages...")
|
self.cmd_helper.notify_update_response("Updating packages...")
|
||||||
try:
|
try:
|
||||||
await self._update_apt(force=True, notify=True)
|
await self._update_apt(force=True, notify=True)
|
||||||
|
@ -832,6 +834,7 @@ class PackageDeploy(BaseDeploy):
|
||||||
self.available_packages = []
|
self.available_packages = []
|
||||||
self.cmd_helper.notify_update_response(
|
self.cmd_helper.notify_update_response(
|
||||||
"Package update finished...", is_complete=True)
|
"Package update finished...", is_complete=True)
|
||||||
|
return True
|
||||||
|
|
||||||
async def _update_apt(self,
|
async def _update_apt(self,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
|
@ -936,22 +939,22 @@ class WebClientDeploy(BaseDeploy):
|
||||||
f"size: {size}\n"
|
f"size: {size}\n"
|
||||||
f"Content Type: {content_type}")
|
f"Content Type: {content_type}")
|
||||||
|
|
||||||
async def update(self) -> None:
|
async def update(self) -> bool:
|
||||||
async with self.mutex:
|
async with self.mutex:
|
||||||
if self.remote_version == "?":
|
if self.remote_version == "?":
|
||||||
await self._get_remote_version()
|
await self._get_remote_version()
|
||||||
if self.remote_version == "?":
|
if self.remote_version == "?":
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
f"Client {self.repo}: Unable to locate update")
|
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
|
dl_url, content_type, size = self.dl_info
|
||||||
if dl_url == "?":
|
if dl_url == "?":
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
f"Client {self.repo}: Invalid download url")
|
f"Client {self.repo}: Invalid download url")
|
||||||
if self.version == self.remote_version:
|
if self.version == self.remote_version:
|
||||||
# Already up to date
|
# 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(
|
self.cmd_helper.notify_update_response(
|
||||||
f"Downloading Client: {self.name}")
|
f"Downloading Client: {self.name}")
|
||||||
with tempfile.TemporaryDirectory(
|
with tempfile.TemporaryDirectory(
|
||||||
|
@ -975,6 +978,7 @@ class WebClientDeploy(BaseDeploy):
|
||||||
tpe, version_path.write_text, self.version)
|
tpe, version_path.write_text, self.version)
|
||||||
self.cmd_helper.notify_update_response(
|
self.cmd_helper.notify_update_response(
|
||||||
f"Client Update Finished: {self.name}", is_complete=True)
|
f"Client Update Finished: {self.name}", is_complete=True)
|
||||||
|
return True
|
||||||
|
|
||||||
def _extract_release(self,
|
def _extract_release(self,
|
||||||
persist_dir: pathlib.Path,
|
persist_dir: pathlib.Path,
|
||||||
|
|
|
@ -339,13 +339,13 @@ class ZipDeploy(AppDeploy):
|
||||||
with zipfile.ZipFile(release_zip) as zf:
|
with zipfile.ZipFile(release_zip) as zf:
|
||||||
zf.extractall(self.path)
|
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:
|
async with self.mutex:
|
||||||
if not self._is_valid:
|
if not self._is_valid:
|
||||||
raise self.log_exc("Update aborted, repo not valid", False)
|
raise self.log_exc("Update aborted, repo not valid", False)
|
||||||
if self.short_version == self.latest_version:
|
if self.short_version == self.latest_version:
|
||||||
# already up to date
|
# already up to date
|
||||||
return
|
return False
|
||||||
self.cmd_helper.notify_update_response(
|
self.cmd_helper.notify_update_response(
|
||||||
f"Updating Application {self.name}...")
|
f"Updating Application {self.name}...")
|
||||||
npm_hash = await self._get_file_hash(self.npm_pkg_json)
|
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._update_repo_state()
|
||||||
await self.restart_service()
|
await self.restart_service()
|
||||||
self.notify_status("Update Finished...", is_complete=True)
|
self.notify_status("Update Finished...", is_complete=True)
|
||||||
|
return True
|
||||||
|
|
||||||
async def recover(self,
|
async def recover(self,
|
||||||
hard: bool = False,
|
hard: bool = False,
|
||||||
|
|
Loading…
Reference in New Issue