dependencies: Set downloading retry parameters in konan.properties

This commit is contained in:
Ilya Matveev
2017-08-15 18:19:47 +07:00
committed by ilmat192
parent 0ae5df4cfb
commit 266047118e
5 changed files with 37 additions and 16 deletions
+4
View File
@@ -20,6 +20,10 @@ dependenciesUrl = http://download.jetbrains.com/kotlin/native
# Don't check dependencies on a server.
# If true, dependency downloader will throw an exception if a dependency isn't found in konan.home.
airplaneMode = false
downloadingAttempts = 10
downloadingAttemptPauseMs = 3000
llvmDebugOptFlags = -O0
# Mac OS X.
+6 -1
View File
@@ -165,6 +165,11 @@ class TgzNativeDep extends NativeDep {
class HelperNativeDep extends TgzNativeDep {
int maxAttempts = Integer.parseInt(
project.rootProject.ext.konanProperties['downloadingAttempts'].toString())
long attemptPauseMs = Long.parseLong(
project.rootProject.ext.konanProperties['downloadingAttemptPauseMs'].toString())
public HelperNativeDep() {
dependsOn(':tools:helpers:jar')
}
@@ -175,7 +180,7 @@ class HelperNativeDep extends TgzNativeDep {
main = "org.jetbrains.kotlin.konan.MainKt"
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime")
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime").artifacts.files
args baseOutDir.canonicalPath, baseUrl, baseName
args baseOutDir.canonicalPath, baseUrl, maxAttempts, attemptPauseMs, baseName
}
}
}
@@ -32,7 +32,9 @@ import kotlin.concurrent.withLock
class DependencyDownloader(dependenciesRoot: File,
val dependenciesUrl: String,
val dependencies: List<String>,
val airplaneMode: Boolean = false) {
val airplaneMode: Boolean = false,
val maxAttempts: Int = DEFAULT_MAX_ATTEMPTS,
val attemptPauseMs: Long = DEFAULT_ATTEMPT_PAUSE_MS) {
val dependenciesDirectory = dependenciesRoot.apply { mkdirs() }
val cacheDirectory = System.getProperty("user.home")?.let {
@@ -94,21 +96,20 @@ class DependencyDownloader(dependenciesRoot: File,
if (!archive.exists()) {
if (!airplaneMode) {
var attempt = 0
var done = false
do {
while(true) {
try {
download(depName, archive)
done = true
break
} catch (e: IOException) {
if (attempt < MAX_ATTEMPTS) {
if (attempt < maxAttempts) {
attempt++
val pauseTime = attempt * ATTEMPT_PAUSE_MS
val pauseTime = attempt * attemptPauseMs
println("Downloading error: ${e.message}.\n" +
"Waiting ${pauseTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$MAX_ATTEMPTS)")
"Waiting ${pauseTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$maxAttempts)")
Thread.sleep(pauseTime)
} else { throw e }
}
} while (!done)
}
} else {
throw RuntimeException("""
Cannot find a dependency locally: $dependency.
@@ -228,8 +229,8 @@ class DependencyDownloader(dependenciesRoot: File,
companion object {
val lock = ReentrantLock()
const val MAX_ATTEMPTS = 10
const val ATTEMPT_PAUSE_MS = 3000L
const val DEFAULT_MAX_ATTEMPTS = 10
const val DEFAULT_ATTEMPT_PAUSE_MS = 3000L
}
fun run() = lock.withLock {
+5 -1
View File
@@ -28,7 +28,11 @@ class Helper0(val dependenciesDir: String,
File(dependenciesDir),
properties.getProperty("dependenciesUrl", "https://download.jetbrains.com/kotlin/native"),
dependencies,
airplaneMode = properties.getProperty("airplaneMode")?.toBoolean() ?: false
airplaneMode = properties.getProperty("airplaneMode")?.toBoolean() ?: false,
maxAttempts = properties.getProperty("downloadingAttempts")?.toInt()
?: DependencyDownloader.DEFAULT_MAX_ATTEMPTS,
attemptPauseMs = properties.getProperty("downloadingAttemptPauseMs")?.toLong()
?: DependencyDownloader.DEFAULT_ATTEMPT_PAUSE_MS
).run()
}
}
+11 -4
View File
@@ -20,13 +20,20 @@ import java.io.File
import java.util.*
// TODO: Add command line keys
// Args: dependencies directory, dependencies url, dependencies list
// Args: dependencies directory, dependencies url, max attempts, attempt pause, dependencies list
fun main(args: Array<String>) {
if (args.size < 2) {
if (args.size < 5) {
System.exit(1)
}
val dependenciesDir = File(args[0])
val dependenciesUrl = args[1]
val dependencies = List<String>(args.size - 2) { args[2 + it] }
DependencyDownloader(dependenciesDir, dependenciesUrl, dependencies).run()
val maxAttempts = args[2].toInt()
val attemptPause = args[3].toLong()
val dependencies = List<String>(args.size - 4) { args[4 + it] }
DependencyDownloader(dependenciesDir,
dependenciesUrl,
dependencies,
maxAttempts = maxAttempts,
attemptPauseMs = attemptPause
).run()
}