Skip to content

Commit b88c504

Browse files
committed
Add retry logic to inkuire fetch
1 parent a47a81a commit b88c504

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

project/Build.scala

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,16 +1331,32 @@ object Build {
13311331
val inkuireLink = s"https://github.com/VirtusLab/Inkuire/releases/download/$inkuireVersion/inkuire.js"
13321332
val inkuireDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "inkuire.js"
13331333
sbt.IO.touch(inkuireDestinationFile)
1334-
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
1335-
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
1336-
val res = try {
1337-
Await.result(result, duration.Duration(60, "sec"))
1338-
} catch {
1339-
case _: TimeoutException =>
1340-
downloadProcess.destroy()
1341-
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
1334+
1335+
def tryFetch(retries: Int, timeout: Int): Unit = {
1336+
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
1337+
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
1338+
try {
1339+
Await.result(result, duration.Duration(timeout, "sec")) match {
1340+
case 0 =>
1341+
case res if retries > 0 =>
1342+
println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
1343+
tryFetch(retries - 1, timeout)
1344+
case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1345+
}
1346+
} catch {
1347+
case e: TimeoutException =>
1348+
if(retries > 0) {
1349+
println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
1350+
tryFetch(retries - 1, timeout)
1351+
}
1352+
else {
1353+
downloadProcess.destroy()
1354+
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
1355+
}
1356+
}
13421357
}
1343-
if(res != 0) throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1358+
1359+
tryFetch(5, 60)
13441360
Seq(inkuireDestinationFile)
13451361
}.taskValue,
13461362
libraryDependencies ++= Dependencies.flexmarkDeps ++ Seq(

0 commit comments

Comments
 (0)