@@ -28,6 +28,7 @@ import de.gesellix.docker.remote.api.core.RequestConfig
2828import de.gesellix.docker.remote.api.core.ResponseType
2929import de.gesellix.docker.remote.api.core.ServerError
3030import de.gesellix.docker.remote.api.core.ServerException
31+ import de.gesellix.docker.remote.api.core.StreamCallback
3132import de.gesellix.docker.remote.api.core.Success
3233import de.gesellix.docker.remote.api.core.SuccessStream
3334import kotlinx.coroutines.cancel
@@ -234,28 +235,37 @@ class ExecApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
234235 * @throws ServerException If the API returns a server error response
235236 */
236237 @Throws(UnsupportedOperationException ::class , ClientException ::class , ServerException ::class )
237- fun execStart (id : String , execStartConfig : ExecStartConfig ? ) {
238+ @JvmOverloads
239+ fun execStart (
240+ id : String , execStartConfig : ExecStartConfig ? ,
241+ callback : StreamCallback <Frame ?>? = null, timeoutMillis : Long? = null /* = 24.hours.toLongMilliseconds()*/
242+ ) {
238243 val localVariableConfig = execStartRequestConfig(id = id, execStartConfig = execStartConfig)
239244
240- // TODO do we need to inspect the exec, because it might have been created with tty==false?
241- // val expectMultiplexedResponse = !(execInspect(id).processConfig?.tty ?: false)
242- val expectMultiplexedResponse = ! (execStartConfig?.tty ? : false )
245+ val expectMultiplexedResponse: Boolean = if (execStartConfig?.tty != null ) {
246+ ! (execStartConfig.tty ? : false )
247+ } else {
248+ ! (execInspect(id).processConfig?.tty ? : false )
249+ }
243250 val localVarResponse = requestFrames(
244251 localVariableConfig, expectMultiplexedResponse
245252 )
246253
247- // TODO the caller of #execStart() should decide about timeout and callback
248- val timeout = Duration .of(1 , ChronoUnit .HOURS )
249- val callback = LoggingCallback <Frame >()
254+ val timeout = if (timeoutMillis == null ) {
255+ Duration .of(10 , ChronoUnit .MINUTES )
256+ } else {
257+ Duration .of(timeoutMillis, ChronoUnit .MILLIS )
258+ }
259+ val actualCallback = callback ? : LoggingCallback <Frame ?>()
250260
251261 when (localVarResponse.responseType) {
252262 ResponseType .Success -> {
253263 runBlocking {
254264 launch {
255265 withTimeoutOrNull(timeout.toMillis()) {
256- callback .onStarting(this @launch::cancel)
257- ((localVarResponse as SuccessStream <* >).data as Flow <Frame >).collect { callback .onNext(it) }
258- callback .onFinished()
266+ actualCallback .onStarting(this @launch::cancel)
267+ ((localVarResponse as SuccessStream <* >).data as Flow <Frame >).collect { actualCallback .onNext(it) }
268+ actualCallback .onFinished()
259269 }
260270 }
261271 }
0 commit comments