update_manager: apply the command lock to initialization

This makes sure that the Klipper and Moonraker git repos are not initialized simultaneously.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-17 17:35:34 -04:00
parent 47902cb03c
commit 48621da6aa
1 changed files with 13 additions and 11 deletions

View File

@ -114,16 +114,17 @@ class UpdateManager:
self._initalize_updaters, list(self.updaters.values())) self._initalize_updaters, list(self.updaters.values()))
async def _initalize_updaters(self, initial_updaters): async def _initalize_updaters(self, initial_updaters):
self.is_refreshing = True async with self.cmd_request_lock:
await self.cmd_helper.init_api_rate_limit() self.is_refreshing = True
for updater in initial_updaters: await self.cmd_helper.init_api_rate_limit()
if isinstance(updater, PackageUpdater): for updater in initial_updaters:
ret = updater.refresh(False) if isinstance(updater, PackageUpdater):
else: ret = updater.refresh(False)
ret = updater.refresh() else:
if asyncio.iscoroutine(ret): ret = updater.refresh()
await ret if asyncio.iscoroutine(ret):
self.is_refreshing = False await ret
self.is_refreshing = False
async def _set_klipper_repo(self): async def _set_klipper_repo(self):
kinfo = self.server.get_klippy_info() kinfo = self.server.get_klippy_info()
@ -139,7 +140,8 @@ class UpdateManager:
return return
kcfg = self.config[f"update_manager static {self.distro} klipper"] kcfg = self.config[f"update_manager static {self.distro} klipper"]
self.updaters['klipper'] = GitUpdater(kcfg, self.cmd_helper, kpath, env) self.updaters['klipper'] = GitUpdater(kcfg, self.cmd_helper, kpath, env)
await self.updaters['klipper'].refresh() async with self.cmd_request_lock:
await self.updaters['klipper'].refresh()
async def _check_klippy_printing(self): async def _check_klippy_printing(self):
klippy_apis = self.server.lookup_plugin('klippy_apis') klippy_apis = self.server.lookup_plugin('klippy_apis')