Browse Source

Added timeout to github api requests.

pull/188/head
weisj 5 years ago
parent
commit
9e59b62547
  1. 1
      build.gradle.kts
  2. 9
      buildSrc/src/main/groovy/DownloadPrebuiltBinaryFromGitHubAction.groovy
  3. 10
      buildSrc/src/main/groovy/UsePrebuiltBinariesWhenUnbuildablePlugin.groovy

1
build.gradle.kts

@ -98,6 +98,7 @@ allprojects {
accessToken = githubAccessToken
manualDownloadUrl =
"https://github.com/weisJ/darklaf/actions?query=workflow%3A%22Build+Native+Libraries%22+is%3Asuccess+branch%3Amaster"
timeout = 50000
}
}
}

9
buildSrc/src/main/groovy/DownloadPrebuiltBinaryFromGitHubAction.groovy

@ -45,6 +45,7 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
private String workflow
private List<String> branches = []
private boolean missingLibraryIsFailure
private int timeout
private String githubAccessToken
private String variant
@ -111,6 +112,10 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
this.branches = branches
}
void setTimeout(int timeout) {
this.timeout = timeout
}
private Map getCacheInfo() {
if (cacheInfo == null) {
LOCK.readLock().lock()
@ -289,6 +294,9 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
if (isOffline()) return Optional.empty()
HttpURLConnection get = new URL(url).openConnection() as HttpURLConnection
get.setRequestMethod("GET")
if (timeout >= 0) {
get.setConnectTimeout(timeout)
}
githubAccessToken?.with {
get.setRequestProperty("Authorization", "token $it")
}
@ -300,6 +308,7 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
log("Could not fetch $url. Response code '$responseCode'.")
}
} catch (IOException ignored) {
error(ignored.getMessage())
}
return Optional.empty()
}

10
buildSrc/src/main/groovy/UsePrebuiltBinariesWhenUnbuildablePlugin.groovy

@ -47,6 +47,7 @@ class UsePrebuiltBinariesWhenUnbuildablePlugin implements Plugin<Project> {
it.manualDownloadUrl = githubArtifactExtension.manualDownloadUrl
it.branches = githubArtifactExtension.branches
it.missingLibraryIsFailure = prebuildExtension.missingLibraryIsFailure
it.timeout = githubArtifactExtension.timeout
}
var.nativeRuntimeFiles.setFrom(prebuiltBinariesTask.map { it.prebuiltBinaryFile })
var.nativeRuntimeFiles.from(new CallableLogger({
@ -110,6 +111,7 @@ class UsePrebuiltBinariesWhenUnbuildablePlugin implements Plugin<Project> {
private String workflow
private String manualDownloadUrl
private String accessToken
private int timeout = 0
private List<String> branches = ["master"]
String getUser() {
@ -136,6 +138,10 @@ class UsePrebuiltBinariesWhenUnbuildablePlugin implements Plugin<Project> {
return branches
}
int getTimeout() {
return timeout
}
void setUser(String user) {
this.user = user
}
@ -159,6 +165,10 @@ class UsePrebuiltBinariesWhenUnbuildablePlugin implements Plugin<Project> {
void setBranches(List<String> branches) {
this.branches = branches
}
void setTimeout(int timeout) {
this.timeout = timeout
}
}
}

Loading…
Cancel
Save