Skip to content

Commit 8e92478

Browse files
authored
Merge pull request #13482 from pikinier20/scaladoc/inkuire-retry
Add retry logic to inkuire fetch
2 parents 4eae6fd + 1200580 commit 8e92478

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

project/Build.scala

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,21 +1326,38 @@ object Build {
13261326
Compile / resourceGenerators += Def.task {
13271327
import _root_.scala.sys.process._
13281328
import _root_.scala.concurrent._
1329+
import _root_.scala.concurrent.duration.Duration
13291330
import ExecutionContext.Implicits.global
13301331
val inkuireVersion = "1.0.0-M3"
13311332
val inkuireLink = s"https://github.com/VirtusLab/Inkuire/releases/download/$inkuireVersion/inkuire.js"
13321333
val inkuireDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "inkuire.js"
13331334
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")
1335+
1336+
def tryFetch(retries: Int, timeout: Duration): Unit = {
1337+
val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run()
1338+
val result: Future[Int] = Future(blocking(downloadProcess.exitValue()))
1339+
try {
1340+
Await.result(result, timeout) match {
1341+
case 0 =>
1342+
case res if retries > 0 =>
1343+
println(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res. $retries retries left")
1344+
tryFetch(retries - 1, timeout)
1345+
case res => throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1346+
}
1347+
} catch {
1348+
case e: TimeoutException =>
1349+
downloadProcess.destroy()
1350+
if (retries > 0) {
1351+
println(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout. $retries retries left")
1352+
tryFetch(retries - 1, timeout)
1353+
}
1354+
else {
1355+
throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout")
1356+
}
1357+
}
13421358
}
1343-
if(res != 0) throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res")
1359+
1360+
tryFetch(5, Duration(60, "s"))
13441361
Seq(inkuireDestinationFile)
13451362
}.taskValue,
13461363
libraryDependencies ++= Dependencies.flexmarkDeps ++ Seq(

0 commit comments

Comments
 (0)