Skip to content

Commit a763e1a

Browse files
algolia-botFluf22millotp
committed
feat(clients): endpoint level timeout part 2 [skip-bc] (generated)
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]>
1 parent 01f3992 commit a763e1a

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

client/src/commonMain/kotlin/com/algolia/client/api/IngestionClient.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,11 @@ public class IngestionClient(
939939
)
940940
return requester.execute(
941941
requestConfig = requestConfig,
942-
requestOptions = requestOptions,
942+
requestOptions = RequestOptions(
943+
readTimeout = 180000.milliseconds,
944+
writeTimeout = 180000.milliseconds,
945+
connectTimeout = 180000.milliseconds,
946+
) + requestOptions,
943947
)
944948
}
945949

@@ -1161,7 +1165,11 @@ public class IngestionClient(
11611165
)
11621166
return requester.execute(
11631167
requestConfig = requestConfig,
1164-
requestOptions = requestOptions,
1168+
requestOptions = RequestOptions(
1169+
readTimeout = 180000.milliseconds,
1170+
writeTimeout = 180000.milliseconds,
1171+
connectTimeout = 180000.milliseconds,
1172+
) + requestOptions,
11651173
)
11661174
}
11671175

@@ -1358,7 +1366,11 @@ public class IngestionClient(
13581366
)
13591367
return requester.execute(
13601368
requestConfig = requestConfig,
1361-
requestOptions = requestOptions,
1369+
requestOptions = RequestOptions(
1370+
readTimeout = 180000.milliseconds,
1371+
writeTimeout = 180000.milliseconds,
1372+
connectTimeout = 180000.milliseconds,
1373+
) + requestOptions,
13621374
)
13631375
}
13641376

@@ -1382,7 +1394,11 @@ public class IngestionClient(
13821394
)
13831395
return requester.execute(
13841396
requestConfig = requestConfig,
1385-
requestOptions = requestOptions,
1397+
requestOptions = RequestOptions(
1398+
readTimeout = 180000.milliseconds,
1399+
writeTimeout = 180000.milliseconds,
1400+
connectTimeout = 180000.milliseconds,
1401+
) + requestOptions,
13861402
)
13871403
}
13881404
}

client/src/commonMain/kotlin/com/algolia/client/extensions/SearchClient.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public suspend fun SearchClient.waitForApiKey(
8181
* @param indexName The index in which to perform the request.
8282
* @param taskID The ID of the task to wait for.
8383
* @param timeout If specified, the method will throw a
84-
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
85-
* elapsed.
84+
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
8685
* @param maxRetries maximum number of retry attempts.
8786
* @param requestOptions additional request configuration.
8887
*/
@@ -130,8 +129,7 @@ public suspend fun SearchClient.waitTask(
130129
*
131130
* @param taskID The ID of the task to wait for.
132131
* @param timeout If specified, the method will throw a
133-
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
134-
* elapsed.
132+
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
135133
* @param maxRetries maximum number of retry attempts.
136134
* @param requestOptions additional request configuration.
137135
*/
@@ -178,8 +176,7 @@ public suspend fun SearchClient.waitAppTask(
178176
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
179177
* the response with it.
180178
* @param timeout If specified, the method will throw a
181-
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
182-
* elapsed.
179+
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
183180
* @param maxRetries Maximum number of retry attempts.
184181
* @param requestOptions Additional request configuration.
185182
*/
@@ -216,8 +213,7 @@ public suspend fun SearchClient.waitKeyUpdate(
216213
* Wait on an API key creation operation.
217214
*
218215
* @param timeout If specified, the method will throw a
219-
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
220-
* elapsed.
216+
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
221217
* @param maxRetries Maximum number of retry attempts.
222218
* @param requestOptions Additional request configuration.
223219
*/
@@ -249,8 +245,7 @@ public suspend fun SearchClient.waitKeyCreation(
249245
*
250246
* @param maxRetries Maximum number of retry attempts.
251247
* @param timeout If specified, the method will throw a
252-
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value in milliseconds is
253-
* elapsed.
248+
* [kotlinx.coroutines.TimeoutCancellationException] after the timeout value is elapsed.
254249
* @param requestOptions Additional request configuration.
255250
*/
256251
public suspend fun SearchClient.waitKeyDelete(

client/src/commonMain/kotlin/com/algolia/client/transport/RequestOptions.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,33 @@ import kotlin.time.Duration
66
/**
77
* Represents options for configuring a request to an endpoint.
88
*
9-
* @property writeTimeout The write timeout for the request in milliseconds.
10-
* @property readTimeout The read timeout for the request in milliseconds.
9+
* @property writeTimeout The write timeout for the request.
10+
* @property readTimeout The read timeout for the request.
11+
* @property connectTimeout The connect timeout for the request.
1112
* @property headers A mutable map of header names to their respective values to be sent with the request.
1213
* @property urlParameters A mutable map of URL parameter names to their respective values to be appended to the request URL.
1314
* @property body A JSON object representing the request body.
1415
*/
1516
public data class RequestOptions(
1617
public val writeTimeout: Duration? = null,
1718
public val readTimeout: Duration? = null,
19+
public val connectTimeout: Duration? = null,
1820
public val headers: Map<String, Any> = emptyMap(),
1921
public val urlParameters: Map<String, Any> = emptyMap(),
2022
public val body: JsonObject? = null,
21-
)
23+
) {
24+
public operator fun plus(other: RequestOptions?): RequestOptions {
25+
if (other == null) {
26+
return this
27+
}
28+
29+
return RequestOptions(
30+
writeTimeout = other.writeTimeout ?: writeTimeout,
31+
readTimeout = other.readTimeout ?: readTimeout,
32+
connectTimeout = other.connectTimeout ?: connectTimeout,
33+
headers = headers + other.headers,
34+
urlParameters = urlParameters + other.urlParameters,
35+
body = other.body ?: body,
36+
)
37+
}
38+
}

client/src/commonMain/kotlin/com/algolia/client/transport/internal/KtorRequester.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public class KtorRequester(
118118
CallType.Read -> requestOptions?.readTimeout ?: readTimeout
119119
CallType.Write -> requestOptions?.writeTimeout ?: writeTimeout
120120
}
121-
connectTimeoutMillis = connectTimeout.inWholeMilliseconds
121+
val connectTimeoutDuration = requestOptions?.connectTimeout ?: connectTimeout
122+
connectTimeoutMillis = connectTimeoutDuration.inWholeMilliseconds
122123
socketTimeoutMillis = timeout.inWholeMilliseconds * (host.retryCount + 1)
123124
}
124125
}

0 commit comments

Comments
 (0)