1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

Remove references to old worker, turn off calibre_db task queue (for now until I can determine if it's needed still), and attempt to re-implement email progress tracking (not working at the moment)

This commit is contained in:
blitzmann 2020-08-22 23:35:48 -04:00
parent 2533c9c14e
commit 414043ded1
6 changed files with 27 additions and 21 deletions

View File

@ -347,7 +347,7 @@ class CalibreDB(threading.Thread):
self.log = logger.create()
def run(self):
while True:
while False:
i = self.queue.get()
if i == 'dummy':
self.queue.task_done()

View File

@ -33,7 +33,7 @@ from flask_login import current_user, login_required
from sqlalchemy.exc import OperationalError
from . import constants, logger, isoLanguages, gdriveutils, uploader, helper
from . import config, get_locale, ub, worker, db
from . import config, get_locale, ub, db
from . import calibre_db
from .services.worker import WorkerThread
from .tasks.upload import TaskUpload

View File

@ -60,16 +60,13 @@ try:
except ImportError:
use_PIL = False
from . import logger, config, get_locale, db, ub, isoLanguages, worker
from . import logger, config, get_locale, db, ub, isoLanguages
from . import gdriveutils as gd
from .constants import STATIC_DIR as _STATIC_DIR
from .pagination import Pagination
from .subproc_wrapper import process_wait
from .worker import STAT_WAITING, STAT_FAIL, STAT_STARTED, STAT_FINISH_SUCCESS
from .worker import TASK_EMAIL, TASK_CONVERT, TASK_UPLOAD, TASK_CONVERT_ANY
from .services.worker import WorkerThread
from .services.worker import WorkerThread, STAT_WAITING, STAT_FAIL, STAT_STARTED, STAT_FINISH_SUCCESS
from .tasks.email import TaskEmail
from . import tasks
log = logger.create()

View File

@ -27,11 +27,11 @@ from cps import gdriveutils
log = logger.create()
chunksize = 8192
CHUNKSIZE = 8192
# Class for sending email with ability to get current progress
class EmailBase():
class EmailBase:
transferSize = 0
progress = 0
@ -52,11 +52,11 @@ class EmailBase():
lock.acquire()
self.transferSize = len(strg)
lock.release()
for i in range(0, self.transferSize, chunksize):
for i in range(0, self.transferSize, CHUNKSIZE):
if isinstance(strg, bytes):
self.sock.send((strg[i:i+chunksize]))
self.sock.send((strg[i:i + CHUNKSIZE]))
else:
self.sock.send((strg[i:i + chunksize]).encode('utf-8'))
self.sock.send((strg[i:i + CHUNKSIZE]).encode('utf-8'))
lock.acquire()
self.progress = i
lock.release()
@ -69,7 +69,7 @@ class EmailBase():
raise smtplib.SMTPServerDisconnected('please run connect() first')
@classmethod
def _print_debug(self, *args):
def _print_debug(cls, *args):
log.debug(args)
def getTransferStatus(self):
@ -78,9 +78,9 @@ class EmailBase():
lock2.acquire()
value = int((float(self.progress) / float(self.transferSize))*100)
lock2.release()
return str(value) + ' %'
return value / 100
else:
return "100 %"
return 1
# Class for sending email with ability to get current progress, derived from emailbase class
@ -106,6 +106,7 @@ class TaskEmail(CalibreTask):
self.filepath = filepath
self.recipent = recipient
self.text = text
self.asyncSMTP = None
self.results = dict()
@ -118,7 +119,7 @@ class TaskEmail(CalibreTask):
text = self.text
msg.attach(MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8'))
if self.attachment:
result = self.get_attachment(self.filepath, self.attachment)
result = self._get_attachment(self.filepath, self.attachment)
if result:
msg.attach(result)
else:
@ -183,7 +184,15 @@ class TaskEmail(CalibreTask):
self._handleError(u'Socket Error sending email: ' + e.strerror)
return None
def _get_attachment(bookpath, filename):
@property
def progress(self):
if self.asyncSMTP is not None:
return self.asyncSMTP.getTransferStatus()
else:
return 0
@classmethod
def _get_attachment(cls, bookpath, filename):
"""Get file as MIMEBase message"""
calibrepath = config.config_calibre_dir
if config.config_use_google_drive:

View File

@ -8,6 +8,7 @@ class TaskUpload(CalibreTask):
super().__init__(taskMessage)
self.start_time = self.end_time = datetime.now()
self.stat = STAT_FINISH_SUCCESS
self.progress = 1
def run(self, worker_thread):
"""Upload task doesn't have anything to do, it's simply a way to add information to the task list"""

View File

@ -51,11 +51,11 @@ except ImportError:
from werkzeug.datastructures import Headers
from werkzeug.security import generate_password_hash, check_password_hash
from . import constants, logger, isoLanguages, services, worker, cli
from . import constants, logger, isoLanguages, services
from . import searched_ids, lm, babel, db, ub, config, get_locale, app
from . import calibre_db
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
from .helper import check_valid_domain, render_task_status, json_serial, \
from .helper import check_valid_domain, render_task_status, \
get_cc_columns, get_book_cover, get_download_link, send_mail, generate_random_password, \
send_registration_mail, check_send_to_kindle, check_read_formats, tags_filters, reset_password
from .pagination import Pagination
@ -386,7 +386,6 @@ def import_ldap_users():
@web.route("/ajax/emailstat")
@login_required
def get_email_status_json():
tasks = WorkerThread.getInstance().tasks
return jsonify(render_task_status(tasks))
@ -976,7 +975,7 @@ def category_list():
@login_required
def get_tasks_status():
# if current user admin, show all email, otherwise only own emails
tasks = worker.get_taskstatus()
tasks = WorkerThread.getInstance().tasks
answer = render_task_status(tasks)
return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"), page="tasks")