mirror of
https://github.com/gotson/komga.git
synced 2025-12-21 07:56:57 +01:00
perf: prevent failing tasks
do not try to generate thumbnail and refresh metadata for books in error
This commit is contained in:
parent
01ab0f7756
commit
07cec50417
2 changed files with 14 additions and 8 deletions
|
|
@ -41,9 +41,10 @@ class TaskHandler(
|
|||
|
||||
is Task.AnalyzeBook ->
|
||||
bookRepository.findByIdOrNull(task.bookId)?.let {
|
||||
bookLifecycle.analyzeAndPersist(it)
|
||||
taskReceiver.generateBookThumbnail(it.id)
|
||||
taskReceiver.refreshBookMetadata(it)
|
||||
if (bookLifecycle.analyzeAndPersist(it)) {
|
||||
taskReceiver.generateBookThumbnail(it.id)
|
||||
taskReceiver.refreshBookMetadata(it)
|
||||
}
|
||||
} ?: logger.warn { "Cannot execute task $task: Book does not exist" }
|
||||
|
||||
is Task.GenerateBookThumbnail ->
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import org.gotson.komga.infrastructure.image.ImageConverter
|
|||
import org.gotson.komga.infrastructure.image.ImageType
|
||||
import org.springframework.stereotype.Service
|
||||
import java.io.File
|
||||
import java.nio.file.AccessDeniedException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
|
|
@ -36,14 +37,17 @@ class BookLifecycle(
|
|||
private val imageConverter: ImageConverter
|
||||
) {
|
||||
|
||||
fun analyzeAndPersist(book: Book) {
|
||||
fun analyzeAndPersist(book: Book): Boolean {
|
||||
logger.info { "Analyze and persist book: $book" }
|
||||
val media = try {
|
||||
bookAnalyzer.analyze(book)
|
||||
val (media, error) = try {
|
||||
bookAnalyzer.analyze(book) to false
|
||||
} catch (ade: AccessDeniedException) {
|
||||
logger.error(ade) { "Error while analyzing book: $book" }
|
||||
Media(status = Media.Status.ERROR, comment = "ERR_1000") to true
|
||||
} catch (ex: Exception) {
|
||||
logger.error(ex) { "Error while analyzing book: $book" }
|
||||
Media(status = Media.Status.ERROR, comment = ex.message)
|
||||
}.copy(bookId = book.id)
|
||||
Media(status = Media.Status.ERROR, comment = "ERR_1005") to true
|
||||
}.let { it.first.copy(bookId = book.id) to it.second }
|
||||
|
||||
// if the number of pages has changed, delete all read progress for that book
|
||||
val previous = mediaRepository.findById(book.id)
|
||||
|
|
@ -52,6 +56,7 @@ class BookLifecycle(
|
|||
}
|
||||
|
||||
mediaRepository.update(media)
|
||||
return !error
|
||||
}
|
||||
|
||||
fun generateThumbnailAndPersist(book: Book) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue