update_manager: add "complete" field to update_repsonse notification

This signals to connected clients that the current update in progress has compelted.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-12-17 07:12:59 -05:00
parent 40b74cefb5
commit fa20d106cf
1 changed files with 13 additions and 6 deletions

View File

@ -165,14 +165,15 @@ class UpdateManager:
decoded = json.loads(resp.body) decoded = json.loads(resp.body)
return decoded return decoded
def notify_update_response(self, resp): def notify_update_response(self, resp, is_complete=False):
resp = resp.strip() resp = resp.strip()
if isinstance(resp, bytes): if isinstance(resp, bytes):
resp = resp.decode() resp = resp.decode()
notification = { notification = {
'message': resp, 'message': resp,
'application': None, 'application': None,
'proc_id': None} 'proc_id': None,
'complete': is_complete}
if self.current_update is not None: if self.current_update is not None:
notification['application'] = self.current_update[0] notification['application'] = self.current_update[0]
notification['proc_id'] = self.current_update[1] notification['proc_id'] = self.current_update[1]
@ -228,10 +229,10 @@ class GitUpdater:
log_msg = f"Repo {self.name}: {msg}" log_msg = f"Repo {self.name}: {msg}"
logging.info(log_msg) logging.info(log_msg)
def _notify_status(self, msg): def _notify_status(self, msg, is_complete=False):
log_msg = f"Repo {self.name}: {msg}" log_msg = f"Repo {self.name}: {msg}"
logging.debug(log_msg) logging.debug(log_msg)
self.notify_update_response(log_msg) self.notify_update_response(log_msg, is_complete)
async def refresh_update_state(self): async def refresh_update_state(self):
self.is_valid = False self.is_valid = False
@ -318,9 +319,12 @@ class GitUpdater:
if self.name == "moonraker": if self.name == "moonraker":
# Launch restart async so the request can return # Launch restart async so the request can return
# before the server restarts # before the server restarts
IOLoop.current().spawn_callback(self.restart_service) self._notify_status("Update Finished...",
is_complete=True)
IOLoop.current().call_later(.1, self.restart_service)
else: else:
await self.restart_service() await self.restart_service()
self._notify_status("Update Finished...", is_complete=True)
async def _install_packages(self): async def _install_packages(self):
# Open install file file and read # Open install file file and read
@ -418,6 +422,8 @@ class PackageUpdater:
f"{APT_CMD} upgrade --yes", timeout=3600., notify=True) f"{APT_CMD} upgrade --yes", timeout=3600., notify=True)
except Exception: except Exception:
raise self.server.error("Error updating system packages") raise self.server.error("Error updating system packages")
self.notify_update_response("Package update finished...",
is_complete=True)
class ClientUpdater: class ClientUpdater:
def __init__(self, umgr, repo, path): def __init__(self, umgr, repo, path):
@ -484,7 +490,8 @@ class ClientUpdater:
if not os.path.exists(version_path): if not os.path.exists(version_path):
with open(version_path, "w") as f: with open(version_path, "w") as f:
f.write(self.version) f.write(self.version)
self.notify_update_response(f"Client Updated: {self.name}") self.notify_update_response(f"Client Updated Finished: {self.name}",
is_complete=True)
def get_update_status(self): def get_update_status(self):
return { return {