def deletePrintJob(self, databaseId): databaseIdAsInt = StringUtils.transformToIntOrNone(databaseId) if (databaseIdAsInt == None): self._logger.error( "Could not delete PrintJob, because not a valid databaseId '" + str(databaseId) + "' maybe not a number") return None with self._database.atomic() as transaction: # Opens new transaction. try: # first delete relations n = FilamentModel.delete().where( FilamentModel.printJob == databaseIdAsInt).execute() n = TemperatureModel.delete().where( TemperatureModel.printJob == databaseIdAsInt).execute() n = CostModel.delete().where( CostModel.printJob == databaseIdAsInt).execute() PrintJobModel.delete_by_id(databaseIdAsInt) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception( "Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient( "PJH-DatabaseManager", "Could not delete the printjob ('" + str(databaseId) + "') from the database. See OctoPrint.log for details!") pass
def deletePrintJob(self, databaseId): with self._database.atomic() as transaction: # Opens new transaction. try: # first delete relations n = FilamentModel.delete().where(FilamentModel.printJob == databaseId).execute() n = TemperatureModel.delete().where(TemperatureModel.printJob == databaseId).execute() PrintJobModel.delete_by_id(databaseId) except Exception as e: # Because this block of code is wrapped with "atomic", a # new transaction will begin automatically after the call # to rollback(). transaction.rollback() self._logger.exception("Could not delete printJob from database:" + str(e)) self.sendErrorMessageToClient("PJH-DatabaseManager", "Could not delete the printjob ('"+ str(databaseId) +"') from the database. See OctoPrint.log for details!") pass