Throttle how often the local cluster updates

This puts it in line with how often the cloud does it
Might contribute to #11608
This commit is contained in:
Jaime van Kessel 2022-09-02 10:03:24 +02:00
parent 89fbac74f9
commit 023046370a
No known key found for this signature in database
GPG key ID: C85F7A3AF1BAA7C4

View file

@ -3,6 +3,8 @@
import os import os
from typing import Optional, Dict, List, Callable, Any from typing import Optional, Dict, List, Callable, Any
from time import time
from PyQt6.QtGui import QDesktopServices from PyQt6.QtGui import QDesktopServices
from PyQt6.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject from PyQt6.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
from PyQt6.QtNetwork import QNetworkReply from PyQt6.QtNetwork import QNetworkReply
@ -32,6 +34,8 @@ class LocalClusterOutputDevice(UltimakerNetworkedPrinterOutputDevice):
activeCameraUrlChanged = pyqtSignal() activeCameraUrlChanged = pyqtSignal()
CHECK_CLUSTER_INTERVAL = 10.0 # seconds
def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], parent=None) -> None: def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], parent=None) -> None:
super().__init__( super().__init__(
@ -107,6 +111,8 @@ class LocalClusterOutputDevice(UltimakerNetworkedPrinterOutputDevice):
def _update(self) -> None: def _update(self) -> None:
super()._update() super()._update()
if time() - self._time_of_last_request < self.CHECK_CLUSTER_INTERVAL:
return # avoid calling the cluster too often
self._getApiClient().getPrinters(self._updatePrinters) self._getApiClient().getPrinters(self._updatePrinters)
self._getApiClient().getPrintJobs(self._updatePrintJobs) self._getApiClient().getPrintJobs(self._updatePrintJobs)
self._updatePrintJobPreviewImages() self._updatePrintJobPreviewImages()