cleanup (remove unused executeWithRetry)

GitOrigin-RevId: 7f2665ba898482a28b24551decb33dcf93c28a04
This commit is contained in:
Vladimir Krivosheev
2024-07-18 06:47:32 +02:00
committed by intellij-monorepo-bot
parent a147a495dc
commit f1534f6d58

View File

@@ -14,15 +14,15 @@ enum class PrintFailuresMode {
ONLY_LAST_FAILURE;
}
/** @return T - if successful; null - otherwise */
suspend fun <T> withRetry(messageOnFailure: String,
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 ->
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()
@@ -71,22 +73,3 @@ fun <T> withRetryBlocking(
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)
}