mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
cleanup (remove unused executeWithRetry)
GitOrigin-RevId: 7f2665ba898482a28b24551decb33dcf93c28a04
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a147a495dc
commit
f1534f6d58
@@ -14,15 +14,15 @@ enum class PrintFailuresMode {
|
||||
ONLY_LAST_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/** @return T - if successful; null - otherwise */
|
||||
suspend fun <T> withRetry(messageOnFailure: String,
|
||||
retries: Long = 3,
|
||||
printFailuresMode: PrintFailuresMode = PrintFailuresMode.ALL_FAILURES,
|
||||
delay: Duration = 10.seconds,
|
||||
retryAction: suspend () -> T): T? {
|
||||
|
||||
(1..retries).forEach { failureCount ->
|
||||
suspend fun <T> withRetry(
|
||||
messageOnFailure: String,
|
||||
retries: Long = 3,
|
||||
printFailuresMode: PrintFailuresMode = PrintFailuresMode.ALL_FAILURES,
|
||||
delay: Duration = 10.seconds,
|
||||
retryAction: suspend () -> T,
|
||||
): T? {
|
||||
for (failureCount in 1..retries) {
|
||||
try {
|
||||
return retryAction()
|
||||
}
|
||||
@@ -30,7 +30,9 @@ suspend fun <T> withRetry(messageOnFailure: String,
|
||||
throw e
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
if (messageOnFailure.isNotBlank()) logError(messageOnFailure)
|
||||
if (messageOnFailure.isNotBlank()) {
|
||||
logError(messageOnFailure)
|
||||
}
|
||||
|
||||
when (printFailuresMode) {
|
||||
PrintFailuresMode.ALL_FAILURES -> t.printStackTrace()
|
||||
@@ -70,23 +72,4 @@ fun <T> withRetryBlocking(
|
||||
printFailuresMode = printFailuresMode,
|
||||
delay = delay
|
||||
) { retryAction() }
|
||||
}
|
||||
|
||||
fun <T> executeWithRetry(retries: Int = 3, exception: Class<*>,
|
||||
errorMsg: String = "Fail to execute action after $retries attempts",
|
||||
delay: Duration,
|
||||
call: () -> T): T {
|
||||
for (i in 0..retries) {
|
||||
try {
|
||||
return call()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
logError("Got error $e on $i attempt")
|
||||
if (e::class.java == exception) {
|
||||
Thread.sleep(delay.inWholeMilliseconds)
|
||||
}
|
||||
else throw e
|
||||
}
|
||||
}
|
||||
throw IllegalStateException(errorMsg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user