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.
# 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
from typing import Dict, List, Optional, Set
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_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
@property
def host_name(self) -> str:
@ -165,9 +167,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
mesh_bytes = mesh_format.getBytes(nodes)
# TODO: Remove extension from the file name, since we are using content types now
request = CloudJobUploadRequest(
job_name = file_name, ## + "." + mesh_format.file_extension,
job_name = file_name,
file_size = len(mesh_bytes),
content_type = mesh_format.mime_type,
)
@ -261,18 +262,15 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
## Handles the event of a change in a print job state
def _onPrintJobStateChanged(self) -> None:
username = self._account.userName
finished_jobs = [job for job in self._print_jobs if job.state == "wait_cleanup"]
newly_finished_jobs = [job for job in finished_jobs if job not in self._finished_jobs and job.owner == username]
for job in newly_finished_jobs:
if job.assignedPrinter:
job_completed_text = T.JOB_COMPLETED_PRINTER.format(printer_name=job.assignedPrinter.name,
job_name=job.name)
else:
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()
user_name = self._getUserName()
for job in self._print_jobs:
if job.state == "wait_cleanup" and job.key not in self._finished_jobs and job.owner == user_name:
self._finished_jobs.add(job.key)
Message(
title = T.JOB_COMPLETED_TITLE,
text = (T.JOB_COMPLETED_PRINTER.format(printer_name=job.assignedPrinter.name, job_name=job.name)
if job.assignedPrinter else T.JOB_COMPLETED_NO_PRINTER.format(job_name=job.name)),
).show()
# Ensure UI gets updated
self.printJobsChanged.emit()
@ -326,13 +324,12 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
def _onUploadError(self, message: str = None) -> None:
self._resetUploadProgress()
if message:
message = Message(
Message(
text = message,
title = T.ERROR,
lifetime = 10,
dismissable = True
)
message.show()
).show()
self._sending_job = False # the upload has finished so we're not sending a job anymore
self.writeError.emit()
@ -341,18 +338,17 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
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)
self._resetUploadProgress()
message = Message(
Message(
text = T.UPLOAD_SUCCESS_TEXT,
title = T.UPLOAD_SUCCESS_TITLE,
lifetime = 5,
dismissable = True,
)
message.show()
).show()
self._sending_job = False # the upload has finished so we're not sending a job anymore
self.writeFinished.emit()
## Gets the remote printers.
@pyqtProperty("QVariantList", notify = _clusterPrintersChanged)
@pyqtProperty("QVariantList", notify=_clusterPrintersChanged)
def printers(self) -> List[PrinterOutputModel]:
return self._printers
@ -374,7 +370,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
## Get remote print jobs.
@pyqtProperty("QVariantList", notify = printJobsChanged)
def printJobs(self)-> List[UM3PrintJobOutputModel]:
def printJobs(self) -> List[UM3PrintJobOutputModel]:
return self._print_jobs
## 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.Logger import Logger
from UM.Message import Message
from cura.API import Account
from cura.CuraApplication import CuraApplication
from cura.Settings.GlobalStack import GlobalStack
from .CloudApiClient import CloudApiClient
@ -40,7 +41,7 @@ class CloudOutputDeviceManager:
application = CuraApplication.getInstance()
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._api = CloudApiClient(self._account, self._onApiError)
@ -54,11 +55,11 @@ class CloudOutputDeviceManager:
self._update_timer.timeout.connect(self._getRemoteClusters)
# 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
def _onLoginStateChanged(self) -> None:
if self._account.isLoggedIn:
def _onLoginStateChanged(self, is_logged_in: bool) -> None:
if is_logged_in:
if not self._update_timer.isActive():
self._update_timer.start()
else: