STAR-322: Fixing finished jobs

This commit is contained in:
Daniel Schiavini 2018-12-07 16:43:53 +01:00
parent 74028c4fa1
commit 63c5b77959
2 changed files with 30 additions and 33 deletions

View file

@ -1,10 +1,9 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import os import os
from datetime import datetime
from time import time from time import time
from typing import Dict, List, Optional from typing import Dict, List, Optional, Set
from PyQt5.QtCore import QObject, QUrl, pyqtProperty, pyqtSignal, pyqtSlot from PyQt5.QtCore import QObject, QUrl, pyqtProperty, pyqtSignal, pyqtSlot
@ -121,6 +120,9 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
self._received_printers = None # type: Optional[List[CloudClusterPrinter]] self._received_printers = None # type: Optional[List[CloudClusterPrinter]]
self._received_print_jobs = None # type: Optional[List[CloudClusterPrintJob]] self._received_print_jobs = None # type: Optional[List[CloudClusterPrintJob]]
# A set of the user's job IDs that have finished
self._finished_jobs = set() # type: Set[str]
## Gets the host name of this device ## Gets the host name of this device
@property @property
def host_name(self) -> str: def host_name(self) -> str:
@ -165,9 +167,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
mesh_bytes = mesh_format.getBytes(nodes) mesh_bytes = mesh_format.getBytes(nodes)
# TODO: Remove extension from the file name, since we are using content types now
request = CloudJobUploadRequest( request = CloudJobUploadRequest(
job_name = file_name, ## + "." + mesh_format.file_extension, job_name = file_name,
file_size = len(mesh_bytes), file_size = len(mesh_bytes),
content_type = mesh_format.mime_type, content_type = mesh_format.mime_type,
) )
@ -261,18 +262,15 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
## Handles the event of a change in a print job state ## Handles the event of a change in a print job state
def _onPrintJobStateChanged(self) -> None: def _onPrintJobStateChanged(self) -> None:
username = self._account.userName user_name = self._getUserName()
finished_jobs = [job for job in self._print_jobs if job.state == "wait_cleanup"] for job in self._print_jobs:
if job.state == "wait_cleanup" and job.key not in self._finished_jobs and job.owner == user_name:
newly_finished_jobs = [job for job in finished_jobs if job not in self._finished_jobs and job.owner == username] self._finished_jobs.add(job.key)
for job in newly_finished_jobs: Message(
if job.assignedPrinter: title = T.JOB_COMPLETED_TITLE,
job_completed_text = T.JOB_COMPLETED_PRINTER.format(printer_name=job.assignedPrinter.name, text = (T.JOB_COMPLETED_PRINTER.format(printer_name=job.assignedPrinter.name, job_name=job.name)
job_name=job.name) if job.assignedPrinter else T.JOB_COMPLETED_NO_PRINTER.format(job_name=job.name)),
else: ).show()
job_completed_text = T.JOB_COMPLETED_NO_PRINTER.format(job_name=job.name)
job_completed_message = Message(text=job_completed_text, title = T.JOB_COMPLETED_TITLE)
job_completed_message.show()
# Ensure UI gets updated # Ensure UI gets updated
self.printJobsChanged.emit() self.printJobsChanged.emit()
@ -326,13 +324,12 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
def _onUploadError(self, message: str = None) -> None: def _onUploadError(self, message: str = None) -> None:
self._resetUploadProgress() self._resetUploadProgress()
if message: if message:
message = Message( Message(
text = message, text = message,
title = T.ERROR, title = T.ERROR,
lifetime = 10, lifetime = 10,
dismissable = True dismissable = True
) ).show()
message.show()
self._sending_job = False # the upload has finished so we're not sending a job anymore self._sending_job = False # the upload has finished so we're not sending a job anymore
self.writeError.emit() self.writeError.emit()
@ -341,18 +338,17 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
def _onUploadSuccess(self, response: CloudPrintResponse) -> None: def _onUploadSuccess(self, response: CloudPrintResponse) -> None:
Logger.log("i", "The cluster will be printing this print job with the ID %s", response.cluster_job_id) Logger.log("i", "The cluster will be printing this print job with the ID %s", response.cluster_job_id)
self._resetUploadProgress() self._resetUploadProgress()
message = Message( Message(
text = T.UPLOAD_SUCCESS_TEXT, text = T.UPLOAD_SUCCESS_TEXT,
title = T.UPLOAD_SUCCESS_TITLE, title = T.UPLOAD_SUCCESS_TITLE,
lifetime = 5, lifetime = 5,
dismissable = True, dismissable = True,
) ).show()
message.show()
self._sending_job = False # the upload has finished so we're not sending a job anymore self._sending_job = False # the upload has finished so we're not sending a job anymore
self.writeFinished.emit() self.writeFinished.emit()
## Gets the remote printers. ## Gets the remote printers.
@pyqtProperty("QVariantList", notify = _clusterPrintersChanged) @pyqtProperty("QVariantList", notify=_clusterPrintersChanged)
def printers(self) -> List[PrinterOutputModel]: def printers(self) -> List[PrinterOutputModel]:
return self._printers return self._printers
@ -374,7 +370,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
## Get remote print jobs. ## Get remote print jobs.
@pyqtProperty("QVariantList", notify = printJobsChanged) @pyqtProperty("QVariantList", notify = printJobsChanged)
def printJobs(self)-> List[UM3PrintJobOutputModel]: def printJobs(self) -> List[UM3PrintJobOutputModel]:
return self._print_jobs return self._print_jobs
## Get remote print jobs that are still in the print queue. ## Get remote print jobs that are still in the print queue.

View file

@ -7,6 +7,7 @@ from PyQt5.QtCore import QTimer
from UM import i18nCatalog from UM import i18nCatalog
from UM.Logger import Logger from UM.Logger import Logger
from UM.Message import Message from UM.Message import Message
from cura.API import Account
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from cura.Settings.GlobalStack import GlobalStack from cura.Settings.GlobalStack import GlobalStack
from .CloudApiClient import CloudApiClient from .CloudApiClient import CloudApiClient
@ -40,7 +41,7 @@ class CloudOutputDeviceManager:
application = CuraApplication.getInstance() application = CuraApplication.getInstance()
self._output_device_manager = application.getOutputDeviceManager() self._output_device_manager = application.getOutputDeviceManager()
self._account = application.getCuraAPI().account self._account = application.getCuraAPI().account # type: Account
self._account.loginStateChanged.connect(self._onLoginStateChanged) self._account.loginStateChanged.connect(self._onLoginStateChanged)
self._api = CloudApiClient(self._account, self._onApiError) self._api = CloudApiClient(self._account, self._onApiError)
@ -54,11 +55,11 @@ class CloudOutputDeviceManager:
self._update_timer.timeout.connect(self._getRemoteClusters) self._update_timer.timeout.connect(self._getRemoteClusters)
# Make sure the timer is started in case we missed the loginChanged signal # Make sure the timer is started in case we missed the loginChanged signal
self._onLoginStateChanged() self._onLoginStateChanged(self._account.isLoggedIn)
# Called when the uses logs in or out # Called when the uses logs in or out
def _onLoginStateChanged(self) -> None: def _onLoginStateChanged(self, is_logged_in: bool) -> None:
if self._account.isLoggedIn: if is_logged_in:
if not self._update_timer.isActive(): if not self._update_timer.isActive():
self._update_timer.start() self._update_timer.start()
else: else: