update_manager: prevent refresh requests from spamming
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
4c68086798
commit
3203950ca9
|
@ -217,7 +217,6 @@ class UpdateManager:
|
||||||
pstate: str = result.get('print_stats', {}).get('state', "")
|
pstate: str = result.get('print_stats', {}).get('state', "")
|
||||||
return pstate.lower() == "printing"
|
return pstate.lower() == "printing"
|
||||||
|
|
||||||
|
|
||||||
async def _handle_auto_refresh(self) -> None:
|
async def _handle_auto_refresh(self) -> None:
|
||||||
if await self._check_klippy_printing():
|
if await self._check_klippy_printing():
|
||||||
# Don't Refresh during a print
|
# Don't Refresh during a print
|
||||||
|
@ -359,16 +358,25 @@ class UpdateManager:
|
||||||
web_request: WebRequest
|
web_request: WebRequest
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
check_refresh = web_request.get_boolean('refresh', False)
|
check_refresh = web_request.get_boolean('refresh', False)
|
||||||
# Don't refresh if a print is currently in progress or
|
# Override a request to refresh if:
|
||||||
# if an update is in progress. Just return the current
|
# - An update is in progress
|
||||||
# state
|
# - Klippy is printing
|
||||||
if self.cmd_helper.is_update_busy() or \
|
if (
|
||||||
await self._check_klippy_printing():
|
self.cmd_helper.is_update_busy() or
|
||||||
|
await self._check_klippy_printing()
|
||||||
|
):
|
||||||
check_refresh = False
|
check_refresh = False
|
||||||
|
|
||||||
if check_refresh:
|
if check_refresh:
|
||||||
# Acquire the command request lock if we want force a refresh
|
# Acquire the command request lock if we want force a refresh
|
||||||
await self.cmd_request_lock.acquire()
|
await self.cmd_request_lock.acquire()
|
||||||
|
# Now that we have acquired the lock reject attempts to spam
|
||||||
|
# the refresh request.
|
||||||
|
lrt = max([upd.get_last_refresh_time()
|
||||||
|
for upd in self.updaters.values()])
|
||||||
|
if time.time() < lrt + 60.:
|
||||||
|
check_refresh = False
|
||||||
|
self.cmd_request_lock.release()
|
||||||
vinfo: Dict[str, Any] = {}
|
vinfo: Dict[str, Any] = {}
|
||||||
try:
|
try:
|
||||||
for name, updater in list(self.updaters.items()):
|
for name, updater in list(self.updaters.items()):
|
||||||
|
|
Loading…
Reference in New Issue