diff --git a/cps/db.py b/cps/db.py index a3075529..46e54706 100644 --- a/cps/db.py +++ b/cps/db.py @@ -352,20 +352,8 @@ class CalibreDB(threading.Thread): if i == 'dummy': self.queue.task_done() break - if i['task'] == 'add_format': - cur_book = self.session.query(Books).filter(Books.id == i['id']).first() - cur_book.data.append(i['format']) - try: - # db.session.merge(cur_book) - self.session.commit() - except OperationalError as e: - self.session.rollback() - self.log.error("Database error: %s", e) - # self._handleError(_(u"Database error: %(error)s.", error=e)) - # return self.queue.task_done() - def stop(self): self.queue.put('dummy') diff --git a/cps/tasks/convert.py b/cps/tasks/convert.py index 58b45d33..cb6d9d81 100644 --- a/cps/tasks/convert.py +++ b/cps/tasks/convert.py @@ -6,6 +6,8 @@ import re from glob import glob from shutil import copyfile +from sqlalchemy.exc import SQLAlchemyError + from cps.services.worker import CalibreTask from cps import calibre_db, db from cps import logger, config @@ -84,9 +86,15 @@ class TaskConvert(CalibreTask): book=book_id, uncompressed_size=os.path.getsize(file_path + format_new_ext)) # todo: this may not be needed anymore, might be able to access the DB directly now. See #1565 - task = {'task':'add_format','id': book_id, 'format': new_format} - self.worker_thread.db_queue.put(task) - # To Do how to handle error? + cur_book = calibre_db.session.query(db.Books).filter(db.Books.id == book_id).first() + cur_book.data.append(new_format) + + try: + # db.session.merge(cur_book) + calibre_db.session.commit() + except SQLAlchemyError as e: + calibre_db.session.rollback() + log.error("Database error: %s", e) '''cur_book.data.append(new_format) try: