Skip to content

Commit 62241e9

Browse files
committed
feat(model-client): added IModelClientV2.pollHash
After adding .pullHash it was just inconsistent to not have a .pollHash.
1 parent 3296665 commit 62241e9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/IModelClientV2.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,11 @@ interface IModelClientV2 {
5555

5656
suspend fun pullHash(branch: BranchReference): String
5757

58+
/**
59+
* While `pull` returns immediately `poll` returns as soon as a new version, that is different from the given
60+
* `lastKnownVersion`, is pushed to the server or after some timout specified by the server (usually ~30 seconds).
61+
*/
5862
suspend fun poll(branch: BranchReference, lastKnownVersion: IVersion?): IVersion
63+
64+
suspend fun pollHash(branch: BranchReference, lastKnownVersion: IVersion?): String
5965
}

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,20 @@ class ModelClientV2(
173173
}
174174
}
175175
val receivedHash: String = response.body()
176-
// LOG.debug { "${clientId.toString(16)}.pullHash($branch) -> $receivedHash" }
176+
return receivedHash
177+
}
178+
179+
override suspend fun pollHash(branch: BranchReference, lastKnownVersion: IVersion?): String {
180+
val response = httpClient.get {
181+
url {
182+
takeFrom(baseUrl)
183+
appendPathSegmentsEncodingSlash("repositories", branch.repositoryId.id, "branches", branch.branchName, "pollHash")
184+
if (lastKnownVersion != null) {
185+
parameters["lastKnown"] = lastKnownVersion.getContentHash()
186+
}
187+
}
188+
}
189+
val receivedHash: String = response.body()
177190
return receivedHash
178191
}
179192

model-server/src/main/kotlin/org/modelix/model/server/handlers/ModelReplicationServer.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ class ModelReplicationServer(val repositoriesManager: RepositoriesManager) {
150150
val newVersionHash = repositoriesManager.pollVersionHash(branchRef(), lastKnownVersionHash)
151151
call.respondDelta(newVersionHash, lastKnownVersionHash)
152152
}
153+
get("pollHash") {
154+
val lastKnownVersionHash = call.request.queryParameters["lastKnown"]
155+
val newVersionHash = repositoriesManager.pollVersionHash(branchRef(), lastKnownVersionHash)
156+
call.respondText(newVersionHash)
157+
}
153158
webSocket("listen") {
154159
var lastVersionHash = call.request.queryParameters["lastKnown"]
155160
while (coroutineContext[Job]?.isCancelled == false) {

0 commit comments

Comments
 (0)