Skip to content

Commit

Permalink
Retry WSLv2 update up to 5 times due to unreliable download server (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Dec 30, 2024
1 parent 3d42bb0 commit 10b7b9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package net.kautler.github.action.setup_wsl

import actions.core.debug
import actions.core.info
import actions.core.isDebug
import actions.exec.ExecOptions
import actions.exec.exec
Expand Down Expand Up @@ -487,16 +486,3 @@ object Alpine : ApkBasedDistribution(
productId = "9p804crf0395",
installerFile = "Alpine.exe"
)

private suspend inline fun <T> retry(amount: Int, crossinline block: suspend () -> T): T {
(1..amount).map { i ->
runCatching {
return block()
}.onFailure {
if (i != 5) {
debug(it.stackTraceToString())
info("Failure happened, retrying (${it.message ?: it})")
}
}
}.last().getOrThrow<Nothing>()
}
17 changes: 17 additions & 0 deletions src/jsMain/kotlin/net/kautler/github/action/setup_wsl/Retry.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.kautler.github.action.setup_wsl

import actions.core.debug
import actions.core.info

internal suspend inline fun <T> retry(amount: Int, crossinline block: suspend () -> T): T {
(1..amount).map { i ->
runCatching {
return block()
}.onFailure {
if (i != 5) {
debug(it.stackTraceToString())
info("Failure happened, retrying (${it.message ?: it})")
}
}
}.last().getOrThrow<Nothing>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,11 @@ suspend fun installDistribution() {
wslArguments = arrayOf("--set-default-version", "${wslVersion()}")
)
if (wslVersion() != 1u) {
executeWslCommand(
wslArguments = arrayOf("--update")
)
retry(5) {
executeWslCommand(
wslArguments = arrayOf("--update")
)
}

(2..30)
.asFlow()
Expand Down

0 comments on commit 10b7b9a

Please sign in to comment.