Reduce number visible System tasks in Tasks list

This commit is contained in:
Ozzie Isaacs 2022-04-22 20:31:03 +02:00
parent 9a8093db31
commit 2f5b9e41ac
3 changed files with 26 additions and 31 deletions

View File

@ -991,7 +991,7 @@ def format_runtime(runtime):
# helper function to apply localize status information in tasklist entries # helper function to apply localize status information in tasklist entries
def render_task_status(tasklist): def render_task_status(tasklist):
renderedtasklist = list() renderedtasklist = list()
for __, user, __, task in tasklist: for __, user, __, task, __ in tasklist:
if user == current_user.name or current_user.role_admin(): if user == current_user.name or current_user.role_admin():
ret = {} ret = {}
if task.start_time: if task.start_time:
@ -1078,7 +1078,8 @@ def get_download_link(book_id, book_format, client):
def clear_cover_thumbnail_cache(book_id): def clear_cover_thumbnail_cache(book_id):
WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id)) WorkerThread.add(None, TaskClearCoverThumbnailCache(book_id, _("Replace Thumbnail for book {}".format(book_id))),
hidden=True)
def delete_thumbnail_cache(): def delete_thumbnail_cache():
@ -1086,4 +1087,4 @@ def delete_thumbnail_cache():
def add_book_to_thumbnail_cache(book_id): def add_book_to_thumbnail_cache(book_id):
WorkerThread.add(None, TaskGenerateCoverThumbnails(book_id)) WorkerThread.add(None, TaskGenerateCoverThumbnails(book_id), hidden=True)

View File

@ -43,7 +43,7 @@ STAT_CANCELLED = 5
# Only retain this many tasks in dequeued list # Only retain this many tasks in dequeued list
TASK_CLEANUP_TRIGGER = 20 TASK_CLEANUP_TRIGGER = 20
QueuedTask = namedtuple('QueuedTask', 'num, user, added, task') QueuedTask = namedtuple('QueuedTask', 'num, user, added, task, hidden')
def _get_main_thread(): def _get_main_thread():
@ -84,7 +84,7 @@ class WorkerThread(threading.Thread):
self.start() self.start()
@classmethod @classmethod
def add(cls, user, task): def add(cls, user, task, hidden=False):
ins = cls.get_instance() ins = cls.get_instance()
ins.num += 1 ins.num += 1
username = user if user is not None else 'System' username = user if user is not None else 'System'
@ -94,6 +94,7 @@ class WorkerThread(threading.Thread):
user=username, user=username,
added=datetime.now(), added=datetime.now(),
task=task, task=task,
hidden=hidden
)) ))
@property @property
@ -114,10 +115,10 @@ class WorkerThread(threading.Thread):
if delta > TASK_CLEANUP_TRIGGER: if delta > TASK_CLEANUP_TRIGGER:
ret = alive ret = alive
else: else:
# otherwise, lop off the oldest dead tasks until we hit the target trigger # otherwise, loop off the oldest dead tasks until we hit the target trigger
ret = sorted(dead, key=lambda x: x.task.end_time)[-TASK_CLEANUP_TRIGGER:] + alive ret = sorted(dead, key=lambda y: y.task.end_time)[-TASK_CLEANUP_TRIGGER:] + alive
self.dequeued = sorted(ret, key=lambda x: x.num) self.dequeued = sorted(ret, key=lambda y: y.num)
# Main thread loop starting the different tasks # Main thread loop starting the different tasks
def run(self): def run(self):
@ -144,11 +145,11 @@ class WorkerThread(threading.Thread):
# sometimes tasks (like Upload) don't actually have work to do and are created as already finished # sometimes tasks (like Upload) don't actually have work to do and are created as already finished
if item.task.stat is STAT_WAITING: if item.task.stat is STAT_WAITING:
# CalibreTask.start() should wrap all exceptions in it's own error handling # CalibreTask.start() should wrap all exceptions in its own error handling
item.task.start(self) item.task.start(self)
# remove self_cleanup tasks from list # remove self_cleanup tasks and hidden "System Tasks" from list
if item.task.self_cleanup: if item.task.self_cleanup or item.hidden:
self.dequeued.remove(item) self.dequeued.remove(item)
self.queue.task_done() self.queue.task_done()
@ -241,14 +242,6 @@ class CalibreTask:
# By default, we're good to clean a task if it's "Done" # By default, we're good to clean a task if it's "Done"
return self.stat in (STAT_FINISH_SUCCESS, STAT_FAIL, STAT_ENDED, STAT_CANCELLED) return self.stat in (STAT_FINISH_SUCCESS, STAT_FAIL, STAT_ENDED, STAT_CANCELLED)
'''@progress.setter
def progress(self, x):
if x > 1:
x = 1
if x < 0:
x = 0
self._progress = x'''
@property @property
def self_cleanup(self): def self_cleanup(self):
return self._self_cleanup return self._self_cleanup

View File

@ -78,13 +78,8 @@ class TaskGenerateCoverThumbnails(CalibreTask):
def run(self, worker_thread): def run(self, worker_thread):
if self.calibre_db.session and use_IM and self.stat != STAT_CANCELLED and self.stat != STAT_ENDED: if self.calibre_db.session and use_IM and self.stat != STAT_CANCELLED and self.stat != STAT_ENDED:
if self.book_id < 0:
self.create_book_cover_thumbnails(self.book_id)
self._handleSuccess()
self.app_db_session.remove()
return
self.message = 'Scanning Books' self.message = 'Scanning Books'
books_with_covers = self.get_books_with_covers() books_with_covers = self.get_books_with_covers(self.book_id)
count = len(books_with_covers) count = len(books_with_covers)
total_generated = 0 total_generated = 0
@ -115,10 +110,12 @@ class TaskGenerateCoverThumbnails(CalibreTask):
self._handleSuccess() self._handleSuccess()
self.app_db_session.remove() self.app_db_session.remove()
def get_books_with_covers(self): def get_books_with_covers(self, book_id=-1):
filter_exp = (db.Books.id == book_id) if book_id != -1 else True
return self.calibre_db.session \ return self.calibre_db.session \
.query(db.Books) \ .query(db.Books) \
.filter(db.Books.has_cover == 1) \ .filter(db.Books.has_cover == 1) \
.filter(filter_exp) \
.all() .all()
def get_book_cover_thumbnails(self, book_id): def get_book_cover_thumbnails(self, book_id):
@ -224,10 +221,13 @@ class TaskGenerateCoverThumbnails(CalibreTask):
@property @property
def name(self): def name(self):
return 'GenerateCoverThumbnails' return 'Cover Thumbnails'
def __str__(self): def __str__(self):
return "GenerateCoverThumbnails" if self.book_id > 0:
return "Add Thumbnail for book {}".format(self.book_id)
else:
return "Generate Cover Thumbnails"
@property @property
def is_cancellable(self): def is_cancellable(self):
@ -434,7 +434,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
@property @property
def name(self): def name(self):
return 'GenerateSeriesThumbnails' return 'Cover Thumbnails'
def __str__(self): def __str__(self):
return "GenerateSeriesThumbnails" return "GenerateSeriesThumbnails"
@ -496,11 +496,12 @@ class TaskClearCoverThumbnailCache(CalibreTask):
@property @property
def name(self): def name(self):
return 'ThumbnailsClear' return 'Cover Thumbnails'
# needed for logging
def __str__(self): def __str__(self):
if self.book_id > 0: if self.book_id > 0:
return "Delete Thumbnail cache for book " + str(self.book_id) return "Replace Thumbnail cache for book " + str(self.book_id)
else: else:
return "Delete Thumbnail cache directory" return "Delete Thumbnail cache directory"