Increase timeouts for Crowdin API build task (#1602)

This commit is contained in:
Harsh Shandilya 2021-12-23 12:45:29 +05:30 committed by GitHub
parent b93f404890
commit 75cc49d51f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ package crowdin
import de.undercouch.gradle.tasks.download.Download
import java.io.File
import java.util.concurrent.TimeUnit
import javax.xml.parsers.DocumentBuilderFactory
import okhttp3.OkHttpClient
import okhttp3.Request
@ -34,6 +35,7 @@ class CrowdinDownloadPlugin : Plugin<Project> {
if (projectName.isEmpty()) {
throw GradleException(EXCEPTION_MESSAGE)
}
val buildOnApi =
tasks.register("buildOnApi") {
doLast {
val login = providers.environmentVariable("CROWDIN_LOGIN").forUseAtConfigurationTime()
@ -45,7 +47,13 @@ class CrowdinDownloadPlugin : Plugin<Project> {
if (!key.isPresent) {
throw GradleException("CROWDIN_PROJECT_KEY environment variable must be set")
}
val client = OkHttpClient()
val client =
OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.callTimeout(10, TimeUnit.SECONDS)
.build()
val url = CROWDIN_BUILD_API_URL.format(projectName, login.get(), key.get())
val request = Request.Builder().url(url).get().build()
client.newCall(request).execute()
@ -53,7 +61,7 @@ class CrowdinDownloadPlugin : Plugin<Project> {
}
val downloadCrowdin =
tasks.register<Download>("downloadCrowdin") {
dependsOn("buildOnApi")
dependsOn(buildOnApi)
src("https://crowdin.com/backend/download/project/$projectName.zip")
dest("$buildDirectory/translations.zip")
overwrite(true)