From f1534f6d585cd752b1aff36485e7b44069e873bc Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 18 Jul 2024 06:47:32 +0200 Subject: [PATCH] cleanup (remove unused executeWithRetry) GitOrigin-RevId: 7f2665ba898482a28b24551decb33dcf93c28a04 --- .../intellij/tools/ide/util/common/retry.kt | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/tools/intellij.tools.ide.util.common/src/com/intellij/tools/ide/util/common/retry.kt b/tools/intellij.tools.ide.util.common/src/com/intellij/tools/ide/util/common/retry.kt index e12730e132ac..8942017d35d0 100644 --- a/tools/intellij.tools.ide.util.common/src/com/intellij/tools/ide/util/common/retry.kt +++ b/tools/intellij.tools.ide.util.common/src/com/intellij/tools/ide/util/common/retry.kt @@ -14,15 +14,15 @@ enum class PrintFailuresMode { ONLY_LAST_FAILURE; } - /** @return T - if successful; null - otherwise */ -suspend fun 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 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 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 withRetryBlocking( printFailuresMode = printFailuresMode, delay = delay ) { retryAction() } -} - -fun 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) -} +} \ No newline at end of file