Skip to content

Commit

Permalink
Override "toString" of DownloadChapter
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda committed Jul 29, 2023
1 parent f5ddbdb commit 96f88eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ object DownloadManager {
downloadQueue.add(newDownloadChapter)
saveDownloadQueue()
downloadSubscriptionSource.publish(newDownloadChapter)
logger.debug { "Added chapter ${chapter.id} to download queue (${manga.title} | ${chapter.name})" }
logger.debug { "Added chapter ${chapter.id} to download queue ($newDownloadChapter)" }
return newDownloadChapter
}

val retryDownload = downloadChapter?.state == Error
if (retryDownload) {
logger.debug { "Chapter ${chapter.id} download failed, retry download (${manga.title} | ${chapter.name})" }
logger.debug { "Chapter ${chapter.id} download failed, retry download ($downloadChapter)" }

downloadChapter?.state = Queued
downloadChapter?.progress = 0f

return downloadChapter
}

logger.debug { "Chapter ${chapter.id} already present in queue (${manga.title} | ${chapter.name})" }
logger.debug { "Chapter ${chapter.id} already present in queue ($downloadChapter)" }
return null
}

Expand All @@ -297,7 +297,7 @@ object DownloadManager {
}

private fun dequeue(chapterDownloads: Set<DownloadChapter>) {
logger.debug { "dequeue ${chapterDownloads.size} chapters [${chapterDownloads.joinToString(separator = ", ") { "${it.manga.title} (${it.mangaId}) - ${it.chapter.name} (${it.chapter.id})" }}]" }
logger.debug { "dequeue ${chapterDownloads.size} chapters [${chapterDownloads.joinToString(separator = ", ") { "$it" }}]" }

downloadQueue.removeAll(chapterDownloads)
saveDownloadQueue()
Expand All @@ -310,7 +310,7 @@ object DownloadManager {
val download = downloadQueue.find { it.mangaId == mangaId && it.chapterIndex == chapterIndex }
?: return

logger.debug { "reorder download ${download.manga.title} (${download.mangaId}) - ${download.chapter.name} (${download.chapter.id}) from ${downloadQueue.indexOf(download)} to $to" }
logger.debug { "reorder download $download from ${downloadQueue.indexOf(download)} to $to" }

downloadQueue -= download
downloadQueue.add(to, download)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Downloader(
(it.state == Queued || (it.state == Error && it.tries < 3)) // 3 re-tries per download
} ?: break

val logContext = "${logger.name} - downloadChapter(${download.manga.title} (${download.mangaId}) - ${download.chapter.name} (${download.chapter.id}))"
val logContext = "${logger.name} - downloadChapter($download))"
val downloadLogger = KotlinLogging.logger(logContext)

downloadLogger.debug { "start" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ class DownloadChapter(
var state: DownloadState = Queued,
var progress: Float = 0f,
var tries: Int = 0
)
) {
override fun toString(): String {
return "${manga.title} ($mangaId) - ${chapter.name} (${chapter.id}) | state= $state, tries= $tries, progress= $progress"
}
}

0 comments on commit 96f88eb

Please sign in to comment.