Skip to content

Instantly share code, notes, and snippets.

@mzorz
Last active January 18, 2019 15:49
Show Gist options
  • Save mzorz/fd3102e88f44b952cb857d489810afa7 to your computer and use it in GitHub Desktop.
Save mzorz/fd3102e88f44b952cb857d489810afa7 to your computer and use it in GitHub Desktop.
test
def waitJitpack(group, module, hash) {
preBuild.dependsOn(tasks.create(name: "waitJitpack-${module}-${hash}") { thisTask ->
def url = "https://jitpack.io/${group.replace('.', '/')}/${module}/${hash}/${module}-${hash}.pom"
def backoffLimit = 7
for (def backoffCount : (0..backoffLimit)) {
def connection = new URL(url).openConnection() as HttpURLConnection
def timeout = (2**backoffCount) * 5 * 1000; // exponential timeout
connection.setConnectTimeout(timeout)
connection.setReadTimeout(timeout)
connection.setRequestMethod("HEAD");
connection.setInstanceFollowRedirects(true)
try {
def responseCode = connection.getResponseCode();
if (responseCode >= 200 && responseCode <= 299) {
// success. Just bail
return
} else {
def responseMessage = connection.getResponseCode();
throw new RuntimeException("Failed reaching Jitpack for ${group}:${module}:${hash}: ${responseMessage}")
}
} catch (SocketTimeoutException ignored) {
if (backoffCount == backoffLimit) {
throw new Exception("Exhausted waiting for Jipack on ${group}:${module}:${hash}")
}
println "Retrying JitPack ${backoffCount+1}/${backoffLimit+1} for ${group}:${module}:${hash}"
} catch (Exception e) {
throw e
}
}
})
return "${group}:${module}:${hash}"
}
ext {
waitJitpack = this.&waitJitpack
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment