Skip to content

Commit

Permalink
feat(clients): endpoint level timeout part 2 [skip-bc] (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4318

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Thomas Raffray <[email protected]>
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
3 people committed Jan 13, 2025
1 parent 01f3992 commit a763e1a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,11 @@ public class IngestionClient(
)
return requester.execute(
requestConfig = requestConfig,
requestOptions = requestOptions,
requestOptions = RequestOptions(
readTimeout = 180000.milliseconds,
writeTimeout = 180000.milliseconds,
connectTimeout = 180000.milliseconds,
) + requestOptions,
)
}

Expand Down Expand Up @@ -1161,7 +1165,11 @@ public class IngestionClient(
)
return requester.execute(
requestConfig = requestConfig,
requestOptions = requestOptions,
requestOptions = RequestOptions(
readTimeout = 180000.milliseconds,
writeTimeout = 180000.milliseconds,
connectTimeout = 180000.milliseconds,
) + requestOptions,
)
}

Expand Down Expand Up @@ -1358,7 +1366,11 @@ public class IngestionClient(
)
return requester.execute(
requestConfig = requestConfig,
requestOptions = requestOptions,
requestOptions = RequestOptions(
readTimeout = 180000.milliseconds,
writeTimeout = 180000.milliseconds,
connectTimeout = 180000.milliseconds,
) + requestOptions,
)
}

Expand All @@ -1382,7 +1394,11 @@ public class IngestionClient(
)
return requester.execute(
requestConfig = requestConfig,
requestOptions = requestOptions,
requestOptions = RequestOptions(
readTimeout = 180000.milliseconds,
writeTimeout = 180000.milliseconds,
connectTimeout = 180000.milliseconds,
) + requestOptions,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public suspend fun SearchClient.waitForApiKey(
* @param indexName The index in which to perform the request.
* @param taskID The ID of the task to wait for.
* @param timeout If specified, the method will throw a
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
* elapsed.
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
* @param maxRetries maximum number of retry attempts.
* @param requestOptions additional request configuration.
*/
Expand Down Expand Up @@ -130,8 +129,7 @@ public suspend fun SearchClient.waitTask(
*
* @param taskID The ID of the task to wait for.
* @param timeout If specified, the method will throw a
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
* elapsed.
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
* @param maxRetries maximum number of retry attempts.
* @param requestOptions additional request configuration.
*/
Expand Down Expand Up @@ -178,8 +176,7 @@ public suspend fun SearchClient.waitAppTask(
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
* the response with it.
* @param timeout If specified, the method will throw a
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
* elapsed.
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
* @param maxRetries Maximum number of retry attempts.
* @param requestOptions Additional request configuration.
*/
Expand Down Expand Up @@ -216,8 +213,7 @@ public suspend fun SearchClient.waitKeyUpdate(
* Wait on an API key creation operation.
*
* @param timeout If specified, the method will throw a
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
* elapsed.
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
* @param maxRetries Maximum number of retry attempts.
* @param requestOptions Additional request configuration.
*/
Expand Down Expand Up @@ -249,8 +245,7 @@ public suspend fun SearchClient.waitKeyCreation(
*
* @param maxRetries Maximum number of retry attempts.
* @param timeout If specified, the method will throw a
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
* elapsed.
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
* @param requestOptions Additional request configuration.
*/
public suspend fun SearchClient.waitKeyDelete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@ import kotlin.time.Duration
/**
* Represents options for configuring a request to an endpoint.
*
* @property writeTimeout The write timeout for the request in milliseconds.
* @property readTimeout The read timeout for the request in milliseconds.
* @property writeTimeout The write timeout for the request.
* @property readTimeout The read timeout for the request.
* @property connectTimeout The connect timeout for the request.
* @property headers A mutable map of header names to their respective values to be sent with the request.
* @property urlParameters A mutable map of URL parameter names to their respective values to be appended to the request URL.
* @property body A JSON object representing the request body.
*/
public data class RequestOptions(
public val writeTimeout: Duration? = null,
public val readTimeout: Duration? = null,
public val connectTimeout: Duration? = null,
public val headers: Map<String, Any> = emptyMap(),
public val urlParameters: Map<String, Any> = emptyMap(),
public val body: JsonObject? = null,
)
) {
public operator fun plus(other: RequestOptions?): RequestOptions {
if (other == null) {
return this
}

return RequestOptions(
writeTimeout = other.writeTimeout ?: writeTimeout,
readTimeout = other.readTimeout ?: readTimeout,
connectTimeout = other.connectTimeout ?: connectTimeout,
headers = headers + other.headers,
urlParameters = urlParameters + other.urlParameters,
body = other.body ?: body,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public class KtorRequester(
CallType.Read -> requestOptions?.readTimeout ?: readTimeout
CallType.Write -> requestOptions?.writeTimeout ?: writeTimeout
}
connectTimeoutMillis = connectTimeout.inWholeMilliseconds
val connectTimeoutDuration = requestOptions?.connectTimeout ?: connectTimeout
connectTimeoutMillis = connectTimeoutDuration.inWholeMilliseconds
socketTimeoutMillis = timeout.inWholeMilliseconds * (host.retryCount + 1)
}
}
Expand Down

0 comments on commit a763e1a

Please sign in to comment.