Merge pull request #8232 from Ultimaker/CloudNetworkConnectionFixes

Cloud network connection fixes
This commit is contained in:
Remco Burema 2020-09-03 09:57:36 +02:00 committed by GitHub
commit 0b22b94950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -109,8 +109,9 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
if self.isConnected(): if self.isConnected():
return return
Logger.log("i", "Attempting to connect to cluster %s", self.key)
super().connect() super().connect()
Logger.log("i", "Connected to cluster %s", self.key)
CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange) CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange)
self._update() self._update()

View File

@ -45,10 +45,6 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
# States indicating if a print job is queued. # States indicating if a print job is queued.
QUEUED_PRINT_JOBS_STATES = {"queued", "error"} QUEUED_PRINT_JOBS_STATES = {"queued", "error"}
# Time in seconds since last network response after which we consider this device offline.
# We set this a bit higher than some of the other intervals to make sure they don't overlap.
NETWORK_RESPONSE_CONSIDER_OFFLINE = 10.0 # seconds
def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType, def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType,
parent=None) -> None: parent=None) -> None:
@ -87,6 +83,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
# The job upload progress message modal. # The job upload progress message modal.
self._progress = PrintJobUploadProgressMessage() self._progress = PrintJobUploadProgressMessage()
self._timeout_time = 30
@pyqtProperty(str, constant=True) @pyqtProperty(str, constant=True)
def address(self) -> str: def address(self) -> str:
"""The IP address of the printer.""" """The IP address of the printer."""
@ -213,8 +211,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
return Duration(seconds).getDisplayString(DurationFormat.Format.Short) return Duration(seconds).getDisplayString(DurationFormat.Format.Short)
def _update(self) -> None: def _update(self) -> None:
self._checkStillConnected()
super()._update() super()._update()
self._checkStillConnected()
def _checkStillConnected(self) -> None: def _checkStillConnected(self) -> None:
"""Check if we're still connected by comparing the last timestamps for network response and the current time. """Check if we're still connected by comparing the last timestamps for network response and the current time.
@ -224,7 +222,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
TODO: it would be nice to have this logic in the managers, but connecting those with signals causes crashes. TODO: it would be nice to have this logic in the managers, but connecting those with signals causes crashes.
""" """
time_since_last_response = time() - self._time_of_last_response time_since_last_response = time() - self._time_of_last_response
if time_since_last_response > self.NETWORK_RESPONSE_CONSIDER_OFFLINE: if time_since_last_response > self._timeout_time:
Logger.log("d", "It has been %s seconds since the last response for outputdevice %s, so assume a timeout", time_since_last_response, self.key)
self.setConnectionState(ConnectionState.Closed) self.setConnectionState(ConnectionState.Closed)
if self.key in CuraApplication.getInstance().getOutputDeviceManager().getOutputDeviceIds(): if self.key in CuraApplication.getInstance().getOutputDeviceManager().getOutputDeviceIds():
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key) CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
@ -241,6 +240,7 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
return return
# Indicate this device is now connected again. # Indicate this device is now connected again.
Logger.log("d", "Reconnecting output device after timeout.")
self.setConnectionState(ConnectionState.Connected) self.setConnectionState(ConnectionState.Connected)
# If the device was already registered we don't need to register it again. # If the device was already registered we don't need to register it again.