Skip to content

Commit

Permalink
Merge pull request #387 from modelix/feature/configurable-timeout-bul…
Browse files Browse the repository at this point in the history
…k-sync

feat(bulk-model-sync-gradle): make request timeout configurable
  • Loading branch information
languitar authored Jan 2, 2024
2 parents 69b3a42 + faf2573 commit 3d41891
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
it.revision.set(serverSource.revision)
it.includedModules.set(syncDirection.includedModules)
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
it.requestTimeoutSeconds.set(serverSource.requestTimeoutSeconds)
}
return exportFromModelServer
}
Expand Down Expand Up @@ -160,6 +161,7 @@ class ModelSyncGradlePlugin : Plugin<Project> {
it.includedModules.set(syncDirection.includedModules)
it.includedModulePrefixes.set(syncDirection.includedModulePrefixes)
it.continueOnError.set(syncDirection.continueOnError)
it.requestTimeoutSeconds.set(serverTarget.requestTimeoutSeconds)
}

project.tasks.register("runSync${syncDirection.name.replaceFirstChar { it.uppercaseChar() }}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ data class LocalTarget(
}
}

private const val DEFAULT_REQUEST_TIMEOUT_SECONDS = 5 * 60

sealed interface ServerEndpoint : SyncEndpoint {
var url: String?
var repositoryId: String?
var branchName: String?
var requestTimeoutSeconds: Int

override fun getValidationErrors(): List<String> {
val errors = mutableListOf<String>()
Expand All @@ -148,6 +151,7 @@ data class ServerSource(
override var url: String? = null,
override var repositoryId: String? = null,
override var branchName: String? = null,
override var requestTimeoutSeconds: Int = DEFAULT_REQUEST_TIMEOUT_SECONDS,
var revision: String? = null,
) : ServerEndpoint {
override fun getValidationErrors(): List<String> {
Expand Down Expand Up @@ -179,6 +183,7 @@ data class ServerTarget(
override var url: String? = null,
override var repositoryId: String? = null,
override var branchName: String? = null,
override var requestTimeoutSeconds: Int = DEFAULT_REQUEST_TIMEOUT_SECONDS,
) : ServerEndpoint {
override fun getValidationErrors(): List<String> {
val errors = mutableListOf<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.modelix.model.lazy.RepositoryId
import org.modelix.model.sync.bulk.ModelExporter
import org.modelix.model.sync.bulk.isModuleIncluded
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds

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

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

@Input
val requestTimeoutSeconds: Property<Int> = of.property(Int::class.java)

@TaskAction
fun export() {
val modelClient = ModelClientV2PlatformSpecificBuilder()
.url(url.get())
.requestTimeout(requestTimeoutSeconds.get().seconds)
.build()
modelClient.use { client ->
runBlocking { client.init() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.modelix.model.sync.bulk.ModelImporter
import org.modelix.model.sync.bulk.importFilesAsRootChildren
import org.modelix.model.sync.bulk.isModuleIncluded
import javax.inject.Inject
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

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

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

@Input
val requestTimeoutSeconds: Property<Int> = of.property(Int::class.java)

@TaskAction
fun import() {
registeredLanguages.get().forEach {
Expand All @@ -81,9 +84,7 @@ abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : De
val branchRef = ModelFacade.createBranchReference(repoId, branchName.get())
val client = ModelClientV2.builder()
.url(url.get())
// Processing large chunks of data on import might take some time. Therefore, extend the request timeout to
// let the model-server do the import.
.requestTimeout(5.minutes)
.requestTimeout(requestTimeoutSeconds.get().seconds)
.build()
val files = inputDir.listFiles()?.filter {
it.extension == "json" && isModuleIncluded(it.nameWithoutExtension, includedModules.get(), includedModulePrefixes.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ If the target branch does not exist on the model-server, it will be created.
|String
|Source model-server revision. Can be used instead of `repositoryId` and `branchName`. Only available in ServerSource.

|`requestTimeoutSeconds`
|Integer
|The request timeout measured in seconds to apply when performing HTTP requests towards the model-server. Default: 5 minutes

|===

== Example
Expand Down

0 comments on commit 3d41891

Please sign in to comment.