update_manager: add individual refresh endpoint

This endpoint allows clients to refresh items on an individual basis
when the "name" parameter is specified.  This endpoint replaces

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-02-06 06:42:56 -05:00
parent f50fa3c5e7
commit c8ad69b902
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 34 additions and 0 deletions

View File

@ -158,6 +158,9 @@ class UpdateManager:
self.server.register_endpoint(
"/machine/update/status", ["GET"],
self._handle_status_request)
self.server.register_endpoint(
"/machine/update/refresh", ["POST"],
self._handle_refresh_request)
self.server.register_endpoint(
"/machine/update/recover", ["POST"],
self._handle_repo_recovery)
@ -425,6 +428,37 @@ class UpdateManager:
)
return ret
async def _handle_refresh_request(
self, web_request: WebRequest
) -> Dict[str, Any]:
name: Optional[str] = web_request.get_str("name", None)
if name is not None and name not in self.updaters:
raise self.server.error(f"No updater registered for '{name}'")
machine: Machine = self.server.lookup_component("machine")
if (
machine.validation_enabled() or
self.cmd_helper.is_update_busy() or
self.kconn.is_printing() or
not self.initial_refresh_complete
):
raise self.server.error(
"Server is busy, cannot perform refresh", 503
)
async with self.cmd_request_lock:
vinfo: Dict[str, Any] = {}
for updater_name, updater in list(self.updaters.items()):
if name is None or updater_name == name:
await updater.refresh()
vinfo[updater_name] = updater.get_update_status()
ret = self.cmd_helper.get_rate_limit_stats()
ret['version_info'] = vinfo
ret['busy'] = self.cmd_helper.is_update_busy()
event_loop = self.server.get_event_loop()
event_loop.delay_callback(
.2, self.cmd_helper.notify_update_refreshed
)
return ret
async def _handle_repo_recovery(self,
web_request: WebRequest
) -> str: