Retry a few times if a favorites sync entry times out
This commit is contained in:
parent
efbdab973e
commit
1f84918749
@ -59,6 +59,7 @@ class GalleryAdder(
|
|||||||
fav: Boolean = false,
|
fav: Boolean = false,
|
||||||
forceSource: UrlImportableSource? = null,
|
forceSource: UrlImportableSource? = null,
|
||||||
throttleFunc: suspend () -> Unit = {},
|
throttleFunc: suspend () -> Unit = {},
|
||||||
|
retry: Int = 1
|
||||||
): GalleryAddEvent {
|
): GalleryAddEvent {
|
||||||
logger.d(context.getString(R.string.gallery_adder_importing_gallery, url, fav.toString(), forceSource))
|
logger.d(context.getString(R.string.gallery_adder_importing_gallery, url, fav.toString(), forceSource))
|
||||||
try {
|
try {
|
||||||
@ -138,7 +139,7 @@ class GalleryAdder(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Fetch and copy details
|
// Fetch and copy details
|
||||||
val newManga = source.getMangaDetails(manga.toSManga())
|
val newManga = retry(retry) { source.getMangaDetails(manga.toSManga()) }
|
||||||
updateManga.awaitUpdateFromSource(manga, newManga, false)
|
updateManga.awaitUpdateFromSource(manga, newManga, false)
|
||||||
manga = getManga.await(manga.id)!!
|
manga = getManga.await(manga.id)!!
|
||||||
|
|
||||||
@ -149,10 +150,12 @@ class GalleryAdder(
|
|||||||
|
|
||||||
// Fetch and copy chapters
|
// Fetch and copy chapters
|
||||||
try {
|
try {
|
||||||
val chapterList = if (source is EHentai) {
|
val chapterList = retry(retry) {
|
||||||
source.getChapterList(manga.toSManga(), throttleFunc)
|
if (source is EHentai) {
|
||||||
} else {
|
source.getChapterList(manga.toSManga(), throttleFunc)
|
||||||
source.getChapterList(manga.toSManga())
|
} else {
|
||||||
|
source.getChapterList(manga.toSManga())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapterList.isNotEmpty()) {
|
if (chapterList.isNotEmpty()) {
|
||||||
@ -186,6 +189,28 @@ class GalleryAdder(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun <T : Any> retry(retryCount: Int, block: () -> T): T {
|
||||||
|
var result: T? = null
|
||||||
|
var lastError: Exception? = null
|
||||||
|
|
||||||
|
for (i in 1..retryCount) {
|
||||||
|
try {
|
||||||
|
result = block()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (e is EHentai.GalleryNotFoundException) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
lastError = e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastError != null) {
|
||||||
|
throw lastError
|
||||||
|
}
|
||||||
|
|
||||||
|
return result!!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class GalleryAddEvent {
|
sealed class GalleryAddEvent {
|
||||||
|
@ -246,7 +246,7 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
errorList += errorString
|
errorList += errorString
|
||||||
} else {
|
} else {
|
||||||
status.value = FavoritesSyncStatus.Error(errorString)
|
status.value = FavoritesSyncStatus.Error(errorString)
|
||||||
throw IgnoredException()
|
throw IgnoredException(errorString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
errorList += errorString
|
errorList += errorString
|
||||||
} else {
|
} else {
|
||||||
status.value = FavoritesSyncStatus.Error(errorString)
|
status.value = FavoritesSyncStatus.Error(errorString)
|
||||||
throw IgnoredException()
|
throw IgnoredException(errorString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,11 +361,12 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
|
|
||||||
// Import using gallery adder
|
// Import using gallery adder
|
||||||
val result = galleryAdder.addGallery(
|
val result = galleryAdder.addGallery(
|
||||||
context,
|
context = context,
|
||||||
"${exh.baseUrl}${it.getUrl()}",
|
url = "${exh.baseUrl}${it.getUrl()}",
|
||||||
true,
|
fav = true,
|
||||||
exh,
|
forceSource = exh,
|
||||||
throttleManager::throttle,
|
throttleFunc = throttleManager::throttle,
|
||||||
|
retry = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
if (result is GalleryAddEvent.Fail) {
|
if (result is GalleryAddEvent.Fail) {
|
||||||
@ -385,7 +386,7 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
errorList += errorString
|
errorList += errorString
|
||||||
} else {
|
} else {
|
||||||
status.value = FavoritesSyncStatus.Error(errorString)
|
status.value = FavoritesSyncStatus.Error(errorString)
|
||||||
throw IgnoredException()
|
throw IgnoredException(errorString)
|
||||||
}
|
}
|
||||||
} else if (result is GalleryAddEvent.Success) {
|
} else if (result is GalleryAddEvent.Success) {
|
||||||
insertedMangaCategories += categories[it.category].id to result.manga
|
insertedMangaCategories += categories[it.category].id to result.manga
|
||||||
@ -401,7 +402,7 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
private fun needWarnThrottle() =
|
private fun needWarnThrottle() =
|
||||||
throttleManager.throttleTime >= THROTTLE_WARN
|
throttleManager.throttleTime >= THROTTLE_WARN
|
||||||
|
|
||||||
class IgnoredException : RuntimeException()
|
class IgnoredException(message: String) : RuntimeException(message)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val THROTTLE_WARN = 1.seconds
|
private val THROTTLE_WARN = 1.seconds
|
||||||
|
@ -68,7 +68,14 @@ class BatchAddScreenModel(
|
|||||||
|
|
||||||
splitGalleries.forEachIndexed { i, s ->
|
splitGalleries.forEachIndexed { i, s ->
|
||||||
ensureActive()
|
ensureActive()
|
||||||
val result = withIOContext { galleryAdder.addGallery(context, s, true) }
|
val result = withIOContext {
|
||||||
|
galleryAdder.addGallery(
|
||||||
|
context = context,
|
||||||
|
url = s,
|
||||||
|
fav = true,
|
||||||
|
retry = 2
|
||||||
|
)
|
||||||
|
}
|
||||||
if (result is GalleryAddEvent.Success) {
|
if (result is GalleryAddEvent.Success) {
|
||||||
succeeded.add(s)
|
succeeded.add(s)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user