mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Throttle WebInterfaceManager requests retries (#1772)
This commit is contained in:
@@ -22,6 +22,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@@ -62,6 +63,7 @@ import java.net.URI
|
|||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import kotlin.time.Duration
|
||||||
import kotlin.time.Duration.Companion.hours
|
import kotlin.time.Duration.Companion.hours
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
@@ -545,6 +547,7 @@ object WebInterfaceManager {
|
|||||||
execute: suspend () -> T,
|
execute: suspend () -> T,
|
||||||
maxRetries: Int = 3,
|
maxRetries: Int = 3,
|
||||||
retryCount: Int = 0,
|
retryCount: Int = 0,
|
||||||
|
timeout: Duration = 2.seconds,
|
||||||
): T {
|
): T {
|
||||||
try {
|
try {
|
||||||
return execute()
|
return execute()
|
||||||
@@ -552,6 +555,7 @@ object WebInterfaceManager {
|
|||||||
log.warn(e) { "(retry $retryCount/$maxRetries) failed due to" }
|
log.warn(e) { "(retry $retryCount/$maxRetries) failed due to" }
|
||||||
|
|
||||||
if (retryCount < maxRetries) {
|
if (retryCount < maxRetries) {
|
||||||
|
delay(timeout.times(retryCount + 1))
|
||||||
return executeWithRetry(log, execute, maxRetries, retryCount + 1)
|
return executeWithRetry(log, execute, maxRetries, retryCount + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user