Skip to content

Commit faf2573

Browse files
committed
feat(bulk-model-sync-gradle): make request timeout configurable
Depending on the size of the model, the import into the model-server might have some long-running HTTP calls. As the default timeout was not sufficient in all cases, it can now be configured by users of the task. This also includes configuration of the request timeout for model-server exports.
1 parent 344f5d8 commit faf2573

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/ModelSyncGradlePlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
106106
it.revision.set(serverSource.revision)
107107
it.includedModules.set(syncDirection.includedModules)
108108
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
109+
it.requestTimeoutSeconds.set(serverSource.requestTimeoutSeconds)
109110
}
110111
return exportFromModelServer
111112
}
@@ -160,6 +161,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
160161
it.includedModules.set(syncDirection.includedModules)
161162
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
162163
it.continueOnError.set(syncDirection.continueOnError)
164+
it.requestTimeoutSeconds.set(serverTarget.requestTimeoutSeconds)
163165
}
164166

165167
project.tasks.register("runSync${syncDirection.name.replaceFirstChar { it.uppercaseChar() }}") {

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/config/ModelSyncGradleSettings.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ data class LocalTarget(
130130
}
131131
}
132132

133+
private const val DEFAULT_REQUEST_TIMEOUT_SECONDS = 5 * 60
134+
133135
sealed interface ServerEndpoint : SyncEndpoint {
134136
var url: String?
135137
var repositoryId: String?
136138
var branchName: String?
139+
var requestTimeoutSeconds: Int
137140

138141
override fun getValidationErrors(): List<String> {
139142
val errors = mutableListOf<String>()
@@ -148,6 +151,7 @@ data class ServerSource(
148151
override var url: String? = null,
149152
override var repositoryId: String? = null,
150153
override var branchName: String? = null,
154+
override var requestTimeoutSeconds: Int = DEFAULT_REQUEST_TIMEOUT_SECONDS,
151155
var revision: String? = null,
152156
) : ServerEndpoint {
153157
override fun getValidationErrors(): List<String> {
@@ -179,6 +183,7 @@ data class ServerTarget(
179183
override var url: String? = null,
180184
override var repositoryId: String? = null,
181185
override var branchName: String? = null,
186+
override var requestTimeoutSeconds: Int = DEFAULT_REQUEST_TIMEOUT_SECONDS,
182187
) : ServerEndpoint {
183188
override fun getValidationErrors(): List<String> {
184189
val errors = mutableListOf<String>()

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/tasks/ExportFromModelServer.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.modelix.model.lazy.RepositoryId
4040
import org.modelix.model.sync.bulk.ModelExporter
4141
import org.modelix.model.sync.bulk.isModuleIncluded
4242
import javax.inject.Inject
43+
import kotlin.time.Duration.Companion.seconds
4344

4445
abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : DefaultTask() {
4546

@@ -67,10 +68,14 @@ abstract class ExportFromModelServer @Inject constructor(of: ObjectFactory) : De
6768
@Input
6869
val includedModulePrefixes: SetProperty<String> = of.setProperty(String::class.java)
6970

71+
@Input
72+
val requestTimeoutSeconds: Property<Int> = of.property(Int::class.java)
73+
7074
@TaskAction
7175
fun export() {
7276
val modelClient = ModelClientV2PlatformSpecificBuilder()
7377
.url(url.get())
78+
.requestTimeout(requestTimeoutSeconds.get().seconds)
7479
.build()
7580
modelClient.use { client ->
7681
runBlocking { client.init() }

bulk-model-sync-gradle/src/main/kotlin/org/modelix/model/sync/bulk/gradle/tasks/ImportIntoModelServer.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import org.modelix.model.sync.bulk.ModelImporter
4040
import org.modelix.model.sync.bulk.importFilesAsRootChildren
4141
import org.modelix.model.sync.bulk.isModuleIncluded
4242
import javax.inject.Inject
43-
import kotlin.time.Duration.Companion.minutes
43+
import kotlin.time.Duration.Companion.seconds
4444

4545
abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : DefaultTask() {
4646

@@ -69,6 +69,9 @@ abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : De
6969
@Input
7070
val continueOnError: Property<Boolean> = of.property(Boolean::class.java)
7171

72+
@Input
73+
val requestTimeoutSeconds: Property<Int> = of.property(Int::class.java)
74+
7275
@TaskAction
7376
fun import() {
7477
registeredLanguages.get().forEach {
@@ -81,9 +84,7 @@ abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : De
8184
val branchRef = ModelFacade.createBranchReference(repoId, branchName.get())
8285
val client = ModelClientV2.builder()
8386
.url(url.get())
84-
// Processing large chunks of data on import might take some time. Therefore, extend the request timeout to
85-
// let the model-server do the import.
86-
.requestTimeout(5.minutes)
87+
.requestTimeout(requestTimeoutSeconds.get().seconds)
8788
.build()
8889
val files = inputDir.listFiles()?.filter {
8990
it.extension == "json" && isModuleIncluded(it.nameWithoutExtension, includedModules.get(), includedModulePrefixes.get())

docs/global/modules/core/pages/reference/component-bulk-model-sync-gradle.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ If the target branch does not exist on the model-server, it will be created.
143143
|String
144144
|Source model-server revision. Can be used instead of `repositoryId` and `branchName`. Only available in ServerSource.
145145

146+
|`requestTimeoutSeconds`
147+
|Integer
148+
|The request timeout measured in seconds to apply when performing HTTP requests towards the model-server. Default: 5 minutes
149+
146150
|===
147151

148152
== Example

0 commit comments

Comments
 (0)