mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 09:30:31 +00:00
Reduce number visible System tasks in Tasks list
This commit is contained in:
parent
9a8093db31
commit
2f5b9e41ac
@ -991,7 +991,7 @@ def format_runtime(runtime):
|
||||
# helper function to apply localize status information in tasklist entries
|
||||
def render_task_status(tasklist):
|
||||
renderedtasklist = list()
|
||||
for __, user, __, task in tasklist:
|
||||
for __, user, __, task, __ in tasklist:
|
||||
if user == current_user.name or current_user.role_admin():
|
||||
ret = {}
|
||||
if task.start_time:
|
||||
@ -1078,7 +1078,8 @@ def get_download_link(book_id, book_format, client):
|
||||
|
||||
|
||||
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():
|
||||
@ -1086,4 +1087,4 @@ def delete_thumbnail_cache():
|
||||
|
||||
|
||||
def add_book_to_thumbnail_cache(book_id):
|
||||
WorkerThread.add(None, TaskGenerateCoverThumbnails(book_id))
|
||||
WorkerThread.add(None, TaskGenerateCoverThumbnails(book_id), hidden=True)
|
||||
|
@ -43,7 +43,7 @@ STAT_CANCELLED = 5
|
||||
# Only retain this many tasks in dequeued list
|
||||
TASK_CLEANUP_TRIGGER = 20
|
||||
|
||||
QueuedTask = namedtuple('QueuedTask', 'num, user, added, task')
|
||||
QueuedTask = namedtuple('QueuedTask', 'num, user, added, task, hidden')
|
||||
|
||||
|
||||
def _get_main_thread():
|
||||
@ -84,7 +84,7 @@ class WorkerThread(threading.Thread):
|
||||
self.start()
|
||||
|
||||
@classmethod
|
||||
def add(cls, user, task):
|
||||
def add(cls, user, task, hidden=False):
|
||||
ins = cls.get_instance()
|
||||
ins.num += 1
|
||||
username = user if user is not None else 'System'
|
||||
@ -94,6 +94,7 @@ class WorkerThread(threading.Thread):
|
||||
user=username,
|
||||
added=datetime.now(),
|
||||
task=task,
|
||||
hidden=hidden
|
||||
))
|
||||
|
||||
@property
|
||||
@ -114,10 +115,10 @@ class WorkerThread(threading.Thread):
|
||||
if delta > TASK_CLEANUP_TRIGGER:
|
||||
ret = alive
|
||||
else:
|
||||
# otherwise, lop 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
|
||||
# otherwise, loop off the oldest dead tasks until we hit the target trigger
|
||||
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
|
||||
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
|
||||
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)
|
||||
|
||||
# remove self_cleanup tasks from list
|
||||
if item.task.self_cleanup:
|
||||
# remove self_cleanup tasks and hidden "System Tasks" from list
|
||||
if item.task.self_cleanup or item.hidden:
|
||||
self.dequeued.remove(item)
|
||||
|
||||
self.queue.task_done()
|
||||
@ -241,14 +242,6 @@ class CalibreTask:
|
||||
# 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)
|
||||
|
||||
'''@progress.setter
|
||||
def progress(self, x):
|
||||
if x > 1:
|
||||
x = 1
|
||||
if x < 0:
|
||||
x = 0
|
||||
self._progress = x'''
|
||||
|
||||
@property
|
||||
def self_cleanup(self):
|
||||
return self._self_cleanup
|
||||
|
@ -78,13 +78,8 @@ class TaskGenerateCoverThumbnails(CalibreTask):
|
||||
|
||||
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.book_id < 0:
|
||||
self.create_book_cover_thumbnails(self.book_id)
|
||||
self._handleSuccess()
|
||||
self.app_db_session.remove()
|
||||
return
|
||||
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)
|
||||
|
||||
total_generated = 0
|
||||
@ -115,10 +110,12 @@ class TaskGenerateCoverThumbnails(CalibreTask):
|
||||
self._handleSuccess()
|
||||
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 \
|
||||
.query(db.Books) \
|
||||
.filter(db.Books.has_cover == 1) \
|
||||
.filter(filter_exp) \
|
||||
.all()
|
||||
|
||||
def get_book_cover_thumbnails(self, book_id):
|
||||
@ -224,10 +221,13 @@ class TaskGenerateCoverThumbnails(CalibreTask):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return 'GenerateCoverThumbnails'
|
||||
return 'Cover Thumbnails'
|
||||
|
||||
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
|
||||
def is_cancellable(self):
|
||||
@ -434,7 +434,7 @@ class TaskGenerateSeriesThumbnails(CalibreTask):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return 'GenerateSeriesThumbnails'
|
||||
return 'Cover Thumbnails'
|
||||
|
||||
def __str__(self):
|
||||
return "GenerateSeriesThumbnails"
|
||||
@ -496,11 +496,12 @@ class TaskClearCoverThumbnailCache(CalibreTask):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return 'ThumbnailsClear'
|
||||
return 'Cover Thumbnails'
|
||||
|
||||
# needed for logging
|
||||
def __str__(self):
|
||||
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:
|
||||
return "Delete Thumbnail cache directory"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user