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 accessToken = githubAccessToken
manualDownloadUrl = manualDownloadUrl =
"https://github.com/weisJ/darklaf/actions?query=workflow%3A%22Build+Native+Libraries%22+is%3Asuccess+branch%3Amaster" "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 String workflow
private List<String> branches = [] private List<String> branches = []
private boolean missingLibraryIsFailure private boolean missingLibraryIsFailure
private int timeout
private String githubAccessToken private String githubAccessToken
private String variant private String variant
@ -111,6 +112,10 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
this.branches = branches this.branches = branches
} }
void setTimeout(int timeout) {
this.timeout = timeout
}
private Map getCacheInfo() { private Map getCacheInfo() {
if (cacheInfo == null) { if (cacheInfo == null) {
LOCK.readLock().lock() LOCK.readLock().lock()
@ -289,6 +294,9 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
if (isOffline()) return Optional.empty() if (isOffline()) return Optional.empty()
HttpURLConnection get = new URL(url).openConnection() as HttpURLConnection HttpURLConnection get = new URL(url).openConnection() as HttpURLConnection
get.setRequestMethod("GET") get.setRequestMethod("GET")
if (timeout >= 0) {
get.setConnectTimeout(timeout)
}
githubAccessToken?.with { githubAccessToken?.with {
get.setRequestProperty("Authorization", "token $it") get.setRequestProperty("Authorization", "token $it")
} }
@ -300,6 +308,7 @@ class DownloadPrebuiltBinaryFromGitHubAction extends DefaultTask {
log("Could not fetch $url. Response code '$responseCode'.") log("Could not fetch $url. Response code '$responseCode'.")
} }
} catch (IOException ignored) { } catch (IOException ignored) {
error(ignored.getMessage())
} }
return Optional.empty() return Optional.empty()
} }

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

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

Loading…
Cancel
Save