mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 09:17:50 -06:00
STAR-322: Checking if response changed before updating cluster
This commit is contained in:
parent
2b8358fda8
commit
5b963de2ea
13 changed files with 58 additions and 30 deletions
|
@ -1,6 +1,7 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from time import time
|
||||
from typing import Dict, List, Optional
|
||||
|
@ -116,6 +117,10 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||
# TODO: handle progress messages in another class.
|
||||
self._progress_message = None # type: Optional[Message]
|
||||
|
||||
# Keep server string of the last generated time to avoid updating models more than once for the same response
|
||||
self._received_printers = None # type: Optional[List[CloudClusterPrinter]]
|
||||
self._received_print_jobs = None # type: Optional[List[CloudClusterPrintJob]]
|
||||
|
||||
## Gets the host name of this device
|
||||
@property
|
||||
def host_name(self) -> str:
|
||||
|
@ -188,7 +193,12 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||
# Contains both printers and print jobs statuses in a single response.
|
||||
def _onStatusCallFinished(self, status: CloudClusterStatus) -> None:
|
||||
# Update all data from the cluster.
|
||||
if self._received_printers != status.printers:
|
||||
self._received_printers = status.printers
|
||||
self._updatePrinters(status.printers)
|
||||
|
||||
if status.print_jobs != self._received_print_jobs:
|
||||
self._received_print_jobs = status.print_jobs
|
||||
self._updatePrintJobs(status.print_jobs)
|
||||
|
||||
## Updates the local list of printers with the list received from the cloud.
|
||||
|
@ -214,7 +224,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||
if not self._active_printer:
|
||||
self.setActivePrinter(self._printers[0])
|
||||
|
||||
self.printersChanged.emit()
|
||||
self.printersChanged.emit() # TODO: Make this more efficient by not updating every request
|
||||
|
||||
## Updates the local list of print jobs with the list received from the cloud.
|
||||
# \param jobs: The print jobs received from the cloud.
|
||||
|
@ -224,11 +234,6 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||
|
||||
removed_jobs, added_jobs, updated_jobs = findChanges(previous, received)
|
||||
|
||||
# TODO: we see that not all data in the UI is correctly updated when the queue and active jobs change.
|
||||
# TODO: we need to fix this here somehow by updating the correct output models.
|
||||
# TODO: the configuration drop down in the slice window is not populated because we are missing some data.
|
||||
# TODO: to fix this we need to implement more data as shown in ClusterUM3OutputDevice._createPrintJobModel
|
||||
|
||||
for removed_job in removed_jobs:
|
||||
self._print_jobs.remove(removed_job)
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from ...Models import BaseModel
|
||||
|
||||
|
||||
class BaseCloudModel(BaseModel):
|
||||
def __eq__(self, other):
|
||||
return type(self) == type(other) and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return type(self) != type(other) or self.__dict__ != other.__dict__
|
||||
|
||||
@staticmethod
|
||||
def parseDate(date_str: str) -> datetime:
|
||||
return datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
|
|
@ -1,10 +1,10 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a cloud connected cluster.
|
||||
class CloudCluster(BaseModel):
|
||||
class CloudCluster(BaseCloudModel):
|
||||
def __init__(self, **kwargs):
|
||||
self.cluster_id = None # type: str
|
||||
self.host_guid = None # type: str
|
||||
|
|
|
@ -6,14 +6,14 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
|||
from plugins.UM3NetworkPrinting.src.Cloud.CloudOutputController import CloudOutputController
|
||||
from .CloudClusterPrinterConfiguration import CloudClusterPrinterConfiguration
|
||||
from .CloudClusterPrintJobConstraint import CloudClusterPrintJobConstraint
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a print job
|
||||
from plugins.UM3NetworkPrinting.src.UM3PrintJobOutputModel import UM3PrintJobOutputModel
|
||||
|
||||
|
||||
class CloudClusterPrintJob(BaseModel):
|
||||
class CloudClusterPrintJob(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.assigned_to = None # type: str
|
||||
self.configuration = [] # type: List[CloudClusterPrinterConfiguration]
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a cloud cluster print job constraint
|
||||
class CloudClusterPrintJobConstraint(BaseModel):
|
||||
class CloudClusterPrintJobConstraint(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.require_printer_name = None # type: str
|
||||
super().__init__(**kwargs)
|
||||
|
|
|
@ -6,11 +6,11 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
|||
from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
|
||||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
from .CloudClusterPrinterConfiguration import CloudClusterPrinterConfiguration
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a cluster printer
|
||||
class CloudClusterPrinter(BaseModel):
|
||||
class CloudClusterPrinter(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.configuration = [] # type: List[CloudClusterPrinterConfiguration]
|
||||
self.enabled = None # type: str
|
||||
|
|
|
@ -6,11 +6,11 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
|||
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
|
||||
from cura.PrinterOutput.ExtruderOutputModel import ExtruderOutputModel
|
||||
from .CloudClusterPrinterConfigurationMaterial import CloudClusterPrinterConfigurationMaterial
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a cloud cluster printer configuration
|
||||
class CloudClusterPrinterConfiguration(BaseModel):
|
||||
class CloudClusterPrinterConfiguration(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.extruder_index = None # type: int
|
||||
self.material = None # type: CloudClusterPrinterConfigurationMaterial
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from UM.Logger import Logger
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing a cloud cluster printer configuration
|
||||
class CloudClusterPrinterConfigurationMaterial(BaseModel):
|
||||
class CloudClusterPrinterConfigurationMaterial(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.guid = None # type: str
|
||||
self.brand = None # type: str
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from .CloudClusterPrinter import CloudClusterPrinter
|
||||
from .CloudClusterPrintJob import CloudClusterPrintJob
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
# Model that represents the status of the cluster for the cloud
|
||||
class CloudClusterStatus(BaseModel):
|
||||
class CloudClusterStatus(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.generated_time = None # type: datetime
|
||||
# a list of the printers
|
||||
self.printers = [] # type: List[CloudClusterPrinter]
|
||||
# a list of the print jobs
|
||||
|
@ -20,3 +22,7 @@ class CloudClusterStatus(BaseModel):
|
|||
# converting any dictionaries into models
|
||||
self.printers = [CloudClusterPrinter(**p) if isinstance(p, dict) else p for p in self.printers]
|
||||
self.print_jobs = [CloudClusterPrintJob(**j) if isinstance(j, dict) else j for j in self.print_jobs]
|
||||
|
||||
# converting generated time into datetime
|
||||
if isinstance(self.generated_time, str):
|
||||
self.generated_time = self.parseDate(self.generated_time)
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from typing import Dict
|
||||
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
## Class representing errors generated by the cloud servers, according to the json-api standard.
|
||||
class CloudErrorObject(BaseModel):
|
||||
class CloudErrorObject(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.id = None # type: str
|
||||
self.code = None # type: str
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
# Model that represents the response received from the cloud after requesting to upload a print job
|
||||
class CloudJobResponse(BaseModel):
|
||||
class CloudJobResponse(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.download_url = None # type: str
|
||||
self.job_id = None # type: str
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
# Model that represents the request to upload a print job to the cloud
|
||||
class CloudJobUploadRequest(BaseModel):
|
||||
class CloudJobUploadRequest(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.file_size = None # type: int
|
||||
self.job_name = None # type: str
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from ...Models import BaseModel
|
||||
from .BaseCloudModel import BaseCloudModel
|
||||
|
||||
|
||||
# Model that represents the responses received from the cloud after requesting a job to be printed.
|
||||
class CloudPrintResponse(BaseModel):
|
||||
class CloudPrintResponse(BaseCloudModel):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.cluster_job_id = None # type: str
|
||||
self.job_id = None # type: str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue