Skip to content

Commit 845b08e

Browse files
committed
Allow custom callbacks at imageCreate()
1 parent dab8bb5 commit 845b08e

File tree

1 file changed

+14
-7
lines changed
  • api-client/src/main/kotlin/de/gesellix/docker/remote/api/client

1 file changed

+14
-7
lines changed

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import de.gesellix.docker.engine.RequestMethod.POST
1818
import de.gesellix.docker.remote.api.BuildInfo
1919
import de.gesellix.docker.remote.api.BuildPruneResponse
2020
import de.gesellix.docker.remote.api.ContainerConfig
21+
import de.gesellix.docker.remote.api.CreateImageInfo
2122
import de.gesellix.docker.remote.api.HistoryResponseItem
2223
import de.gesellix.docker.remote.api.IdResponse
2324
import de.gesellix.docker.remote.api.Image
@@ -571,6 +572,7 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro
571572
* @throws ServerException If the API returns a server error response
572573
*/
573574
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
575+
@JvmOverloads
574576
fun imageCreate(
575577
fromImage: String?,
576578
fromSrc: String?,
@@ -580,7 +582,8 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro
580582
xRegistryAuth: String?,
581583
changes: List<String>?,
582584
platform: String?,
583-
inputImage: InputStream?
585+
inputImage: InputStream?,
586+
callback: StreamCallback<CreateImageInfo?>? = null, timeoutMillis: Long? = null /*= 24.hours.toLongMilliseconds()*/
584587
) {
585588
val localVariableConfig =
586589
imageCreateRequestConfig(
@@ -595,21 +598,25 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro
595598
inputImage = inputImage
596599
)
597600

598-
val localVarResponse = requestStream<Any?>(
601+
val localVarResponse = requestStream<CreateImageInfo?>(
599602
localVariableConfig
600603
)
601604

602-
val timeout = Duration.of(1, ChronoUnit.MINUTES)
603-
val callback = LoggingCallback<Any>()
605+
val timeout = if (timeoutMillis == null) {
606+
Duration.of(10, ChronoUnit.MINUTES)
607+
} else {
608+
Duration.of(timeoutMillis, ChronoUnit.MILLIS)
609+
}
610+
val actualCallback = callback ?: LoggingCallback<CreateImageInfo?>()
604611

605612
return when (localVarResponse.responseType) {
606613
ResponseType.Success -> {
607614
runBlocking {
608615
launch {
609616
withTimeout(timeout.toMillis()) {
610-
callback.onStarting(this@launch::cancel)
611-
(localVarResponse as SuccessStream<*>).data.collect { callback.onNext(it) }
612-
callback.onFinished()
617+
actualCallback.onStarting(this@launch::cancel)
618+
((localVarResponse as SuccessStream<*>).data as Flow<CreateImageInfo?>).collect { actualCallback.onNext(it) }
619+
actualCallback.onFinished()
613620
}
614621
}
615622
}

0 commit comments

Comments
 (0)