Add button to update cover cache (for usecase sideloaded changed cover)

Bugfix logig start background schedue
This commit is contained in:
Ozzie Isaacs 2022-04-25 08:24:14 +02:00
parent 1e723dff3a
commit ae9a970782
7 changed files with 47 additions and 13 deletions

View File

@ -44,7 +44,7 @@ from . import constants, logger, helper, services, cli
from . import db, calibre_db, ub, web_server, get_locale, config, updater_thread, babel, gdriveutils, \
kobo_sync_status, schedule
from .helper import check_valid_domain, send_test_mail, reset_password, generate_password_hash, check_email, \
valid_email, check_username
valid_email, check_username, update_thumbnail_cache
from .gdriveutils import is_gdrive_ready, gdrive_support
from .render_template import render_title_template, get_sidebar_config
from .services.worker import WorkerThread
@ -169,6 +169,17 @@ def reconnect():
abort(404)
@admi.route("/ajax/updateThumbnails", methods=['POST'])
@admin_required
@login_required
def update_thumbnails():
content = config.get_scheduled_task_settings()
if content['schedule_generate_book_covers']:
log.info("Update of Cover cache requested")
update_thumbnail_cache()
return ""
@admi.route("/admin/view")
@login_required
@admin_required
@ -612,6 +623,8 @@ def load_dialogtexts(element_id):
texts["main"] = _('Are you sure you want to change shelf sync behavior for the selected user(s)?')
elif element_id == "db_submit":
texts["main"] = _('Are you sure you want to change Calibre library location?')
elif element_id == "admin_refresh_cover_cache":
texts["main"] = _('Calibre-Web will search for updated Covers and update Cover Thumbnails, this may take a while?')
elif element_id == "btnfullsync":
texts["main"] = _("Are you sure you want delete Calibre-Web's sync database "
"to force a full sync with your Kobo Reader?")

View File

@ -1091,3 +1091,7 @@ def delete_thumbnail_cache():
def add_book_to_thumbnail_cache(book_id):
WorkerThread.add(None, TaskGenerateCoverThumbnails(book_id), hidden=True)
def update_thumbnail_cache():
WorkerThread.add(None, TaskGenerateCoverThumbnails())

View File

@ -30,16 +30,16 @@ def get_scheduled_tasks(reconnect=True):
# Reconnect Calibre database (metadata.db)
if reconnect:
tasks.append([lambda: TaskReconnectDatabase(), 'reconnect'])
tasks.append([lambda: TaskReconnectDatabase(), 'reconnect', False])
# Generate all missing book cover thumbnails
if config.schedule_generate_book_covers:
tasks.append([lambda: TaskGenerateCoverThumbnails(), 'generate book covers'])
tasks.append([lambda: TaskClearCoverThumbnailCache(0), 'delete superfluous book covers'])
tasks.append([lambda: TaskGenerateCoverThumbnails(), 'generate book covers', False])
tasks.append([lambda: TaskClearCoverThumbnailCache(0), 'delete superfluous book covers', True])
# Generate all missing series thumbnails
if config.schedule_generate_series_covers:
tasks.append([lambda: TaskGenerateSeriesThumbnails(), 'generate book covers'])
tasks.append([lambda: TaskGenerateSeriesThumbnails(), 'generate book covers', False])
return tasks
@ -86,4 +86,4 @@ def register_startup_tasks():
def should_task_be_running(start, end):
now = datetime.datetime.now().hour
return (start < end and start <= now < end) or (end < start <= now or now < end)
return (start < end and start <= now < end) or (end < start and (now < end or start <= now ))

View File

@ -52,32 +52,32 @@ class BackgroundScheduler:
return self.scheduler.add_job(func=func, trigger=trigger, name=name, **trigger_args)
# Expects a lambda expression for the task
def schedule_task(self, task, user=None, name=None, trigger='cron', **trigger_args):
def schedule_task(self, task, user=None, name=None, hidden=False, trigger='cron', **trigger_args):
if use_APScheduler:
def scheduled_task():
worker_task = task()
worker_task.scheduled = True
WorkerThread.add(user, worker_task)
WorkerThread.add(user, worker_task, hidden=hidden)
return self.schedule(func=scheduled_task, trigger=trigger, name=name, **trigger_args)
# Expects a list of lambda expressions for the tasks
def schedule_tasks(self, tasks, user=None, trigger='cron', **trigger_args):
if use_APScheduler:
for task in tasks:
self.schedule_task(task[0], user=user, trigger=trigger, name=task[1], **trigger_args)
self.schedule_task(task[0], user=user, trigger=trigger, name=task[1], hidden=task[2], **trigger_args)
# Expects a lambda expression for the task
def schedule_task_immediately(self, task, user=None, name=None):
def schedule_task_immediately(self, task, user=None, name=None, hidden=False):
if use_APScheduler:
def immediate_task():
WorkerThread.add(user, task())
WorkerThread.add(user, task(), hidden)
return self.schedule(func=immediate_task, trigger='date', name=name)
# Expects a list of lambda expressions for the tasks
def schedule_tasks_immediately(self, tasks, user=None):
if use_APScheduler:
for task in tasks:
self.schedule_task_immediately(task[0], user, name="immediately " + task[1])
self.schedule_task_immediately(task[0], user, name="immediately " + task[1], hidden=task[2])
# Remove all jobs
def remove_all_jobs(self):

View File

@ -474,6 +474,17 @@ $(function() {
}
});
});
$("#admin_refresh_cover_cache").click(function() {
confirmDialog("admin_refresh_cover_cache", "GeneralChangeModal", 0, function () {
$.ajax({
method:"post",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: getPath() + "/ajax/updateThumbnails",
});
});
});
$("#restart_database").click(function() {
$("#DialogHeader").addClass("hidden");
$("#DialogFinished").addClass("hidden");

View File

@ -550,7 +550,7 @@ $(function() {
$("#user-table").on("click-cell.bs.table", function (field, value, row, $element) {
if (value === "denied_column_value") {
ConfirmDialog("btndeluser", "GeneralDeleteModal", $element.id, user_handle);
confirmDialog("btndeluser", "GeneralDeleteModal", $element.id, user_handle);
}
});

View File

@ -184,6 +184,9 @@
</div-->
</div>
<a class="btn btn-default scheduledtasks" id="admin_edit_scheduled_tasks" href="{{url_for('admin.edit_scheduledtasks')}}">{{_('Edit Scheduled Tasks Settings')}}</a>
{% if config.schedule_generate_book_covers %}
<a class="btn btn-default" id="admin_refresh_cover_cache">{{_('Refresh Thumbnail Cover Cache')}}</a>
{% endif %}
</div>
</div>
@ -279,3 +282,6 @@
</div>
</div>
{% endblock %}
{% block modal %}
{{ change_confirm_modal() }}
{% endblock %}