mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 12:30:00 +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:
parent
2533c9c14e
commit
414043ded1
@ -347,7 +347,7 @@ class CalibreDB(threading.Thread):
|
|||||||
self.log = logger.create()
|
self.log = logger.create()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while False:
|
||||||
i = self.queue.get()
|
i = self.queue.get()
|
||||||
if i == 'dummy':
|
if i == 'dummy':
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
@ -33,7 +33,7 @@ from flask_login import current_user, login_required
|
|||||||
from sqlalchemy.exc import OperationalError
|
from sqlalchemy.exc import OperationalError
|
||||||
|
|
||||||
from . import constants, logger, isoLanguages, gdriveutils, uploader, helper
|
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 . import calibre_db
|
||||||
from .services.worker import WorkerThread
|
from .services.worker import WorkerThread
|
||||||
from .tasks.upload import TaskUpload
|
from .tasks.upload import TaskUpload
|
||||||
|
@ -60,16 +60,13 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
use_PIL = False
|
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 . import gdriveutils as gd
|
||||||
from .constants import STATIC_DIR as _STATIC_DIR
|
from .constants import STATIC_DIR as _STATIC_DIR
|
||||||
from .pagination import Pagination
|
from .pagination import Pagination
|
||||||
from .subproc_wrapper import process_wait
|
from .subproc_wrapper import process_wait
|
||||||
from .worker import STAT_WAITING, STAT_FAIL, STAT_STARTED, STAT_FINISH_SUCCESS
|
from .services.worker import WorkerThread, 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 .tasks.email import TaskEmail
|
from .tasks.email import TaskEmail
|
||||||
from . import tasks
|
|
||||||
|
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
|
@ -27,11 +27,11 @@ from cps import gdriveutils
|
|||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
|
|
||||||
chunksize = 8192
|
CHUNKSIZE = 8192
|
||||||
|
|
||||||
|
|
||||||
# Class for sending email with ability to get current progress
|
# Class for sending email with ability to get current progress
|
||||||
class EmailBase():
|
class EmailBase:
|
||||||
|
|
||||||
transferSize = 0
|
transferSize = 0
|
||||||
progress = 0
|
progress = 0
|
||||||
@ -52,11 +52,11 @@ class EmailBase():
|
|||||||
lock.acquire()
|
lock.acquire()
|
||||||
self.transferSize = len(strg)
|
self.transferSize = len(strg)
|
||||||
lock.release()
|
lock.release()
|
||||||
for i in range(0, self.transferSize, chunksize):
|
for i in range(0, self.transferSize, CHUNKSIZE):
|
||||||
if isinstance(strg, bytes):
|
if isinstance(strg, bytes):
|
||||||
self.sock.send((strg[i:i+chunksize]))
|
self.sock.send((strg[i:i + CHUNKSIZE]))
|
||||||
else:
|
else:
|
||||||
self.sock.send((strg[i:i + chunksize]).encode('utf-8'))
|
self.sock.send((strg[i:i + CHUNKSIZE]).encode('utf-8'))
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
self.progress = i
|
self.progress = i
|
||||||
lock.release()
|
lock.release()
|
||||||
@ -69,7 +69,7 @@ class EmailBase():
|
|||||||
raise smtplib.SMTPServerDisconnected('please run connect() first')
|
raise smtplib.SMTPServerDisconnected('please run connect() first')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _print_debug(self, *args):
|
def _print_debug(cls, *args):
|
||||||
log.debug(args)
|
log.debug(args)
|
||||||
|
|
||||||
def getTransferStatus(self):
|
def getTransferStatus(self):
|
||||||
@ -78,9 +78,9 @@ class EmailBase():
|
|||||||
lock2.acquire()
|
lock2.acquire()
|
||||||
value = int((float(self.progress) / float(self.transferSize))*100)
|
value = int((float(self.progress) / float(self.transferSize))*100)
|
||||||
lock2.release()
|
lock2.release()
|
||||||
return str(value) + ' %'
|
return value / 100
|
||||||
else:
|
else:
|
||||||
return "100 %"
|
return 1
|
||||||
|
|
||||||
|
|
||||||
# Class for sending email with ability to get current progress, derived from emailbase class
|
# 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.filepath = filepath
|
||||||
self.recipent = recipient
|
self.recipent = recipient
|
||||||
self.text = text
|
self.text = text
|
||||||
|
self.asyncSMTP = None
|
||||||
|
|
||||||
self.results = dict()
|
self.results = dict()
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ class TaskEmail(CalibreTask):
|
|||||||
text = self.text
|
text = self.text
|
||||||
msg.attach(MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8'))
|
msg.attach(MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8'))
|
||||||
if self.attachment:
|
if self.attachment:
|
||||||
result = self.get_attachment(self.filepath, self.attachment)
|
result = self._get_attachment(self.filepath, self.attachment)
|
||||||
if result:
|
if result:
|
||||||
msg.attach(result)
|
msg.attach(result)
|
||||||
else:
|
else:
|
||||||
@ -183,7 +184,15 @@ class TaskEmail(CalibreTask):
|
|||||||
self._handleError(u'Socket Error sending email: ' + e.strerror)
|
self._handleError(u'Socket Error sending email: ' + e.strerror)
|
||||||
return None
|
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"""
|
"""Get file as MIMEBase message"""
|
||||||
calibrepath = config.config_calibre_dir
|
calibrepath = config.config_calibre_dir
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
|
@ -8,6 +8,7 @@ class TaskUpload(CalibreTask):
|
|||||||
super().__init__(taskMessage)
|
super().__init__(taskMessage)
|
||||||
self.start_time = self.end_time = datetime.now()
|
self.start_time = self.end_time = datetime.now()
|
||||||
self.stat = STAT_FINISH_SUCCESS
|
self.stat = STAT_FINISH_SUCCESS
|
||||||
|
self.progress = 1
|
||||||
|
|
||||||
def run(self, worker_thread):
|
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"""
|
"""Upload task doesn't have anything to do, it's simply a way to add information to the task list"""
|
||||||
|
@ -51,11 +51,11 @@ except ImportError:
|
|||||||
from werkzeug.datastructures import Headers
|
from werkzeug.datastructures import Headers
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
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 searched_ids, lm, babel, db, ub, config, get_locale, app
|
||||||
from . import calibre_db
|
from . import calibre_db
|
||||||
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
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, \
|
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
|
send_registration_mail, check_send_to_kindle, check_read_formats, tags_filters, reset_password
|
||||||
from .pagination import Pagination
|
from .pagination import Pagination
|
||||||
@ -386,7 +386,6 @@ def import_ldap_users():
|
|||||||
@web.route("/ajax/emailstat")
|
@web.route("/ajax/emailstat")
|
||||||
@login_required
|
@login_required
|
||||||
def get_email_status_json():
|
def get_email_status_json():
|
||||||
|
|
||||||
tasks = WorkerThread.getInstance().tasks
|
tasks = WorkerThread.getInstance().tasks
|
||||||
return jsonify(render_task_status(tasks))
|
return jsonify(render_task_status(tasks))
|
||||||
|
|
||||||
@ -976,7 +975,7 @@ def category_list():
|
|||||||
@login_required
|
@login_required
|
||||||
def get_tasks_status():
|
def get_tasks_status():
|
||||||
# if current user admin, show all email, otherwise only own emails
|
# if current user admin, show all email, otherwise only own emails
|
||||||
tasks = worker.get_taskstatus()
|
tasks = WorkerThread.getInstance().tasks
|
||||||
answer = render_task_status(tasks)
|
answer = render_task_status(tasks)
|
||||||
return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"), page="tasks")
|
return render_title_template('tasks.html', entries=answer, title=_(u"Tasks"), page="tasks")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user