Skip to content

Commit 23ccb49

Browse files
author
Oleksandr Dzhychko
committed
fix(bulk-model-sync): dispose model client after import into model server
This closes the underlying http client.
1 parent 57bc7f2 commit 23ccb49

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,21 @@ abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : De
7373
val metaProperties: MapProperty<String, String> = of.mapProperty(String::class.java, String::class.java)
7474

7575
@TaskAction
76-
fun import() {
76+
fun import() = runBlocking {
7777
val inputDir = inputDir.get().asFile
7878
val repoId = RepositoryId(repositoryId.get())
7979

8080
val branchRef = ModelFacade.createBranchReference(repoId, branchName.get())
81-
val client = ModelClientV2.builder()
82-
.url(url.get())
83-
.requestTimeout(requestTimeoutSeconds.get().seconds)
84-
.build()
8581
val files = inputDir.listFiles()?.filter {
8682
it.extension == "json" && isModuleIncluded(it.nameWithoutExtension, includedModules.get(), includedModulePrefixes.get())
8783
}
8884
if (files.isNullOrEmpty()) error("no json files found for included modules")
8985

90-
runBlocking {
86+
val client = ModelClientV2.builder()
87+
.url(url.get())
88+
.requestTimeout(requestTimeoutSeconds.get().seconds)
89+
.build()
90+
client.use {
9191
logger.info("Initializing client...")
9292
client.init()
9393
logger.info("Importing...")
@@ -108,6 +108,7 @@ abstract class ImportIntoModelServer @Inject constructor(of: ObjectFactory) : De
108108
logger.info("Sending diff to server...")
109109
}
110110
}
111+
111112
logger.info("Import finished.")
112113
}
113114
}

0 commit comments

Comments
 (0)