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 <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
3 people committed Jan 13, 2025
1 parent 1ef4651 commit 6e71ebc
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/AbtestingClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ object AbtestingClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(region: Option[String] = None): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/AnalyticsClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ object AnalyticsClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(region: Option[String] = None): Seq[Host] = {
Expand Down
50 changes: 43 additions & 7 deletions src/main/scala/algoliasearch/api/IngestionClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ object IngestionClient {
)

private def readTimeout(): Duration = {
Duration(25, TimeUnit.SECONDS)
Duration(25000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(25, TimeUnit.SECONDS)
Duration(25000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(25, TimeUnit.SECONDS)
Duration(25000, TimeUnit.MILLISECONDS)
}

private def hosts(region: String): Seq[Host] = {
Expand Down Expand Up @@ -1223,7 +1223,16 @@ class IngestionClient(
.withBody(pushTaskPayload)
.withQueryParameter("watch", watch)
.build()
execute[WatchResponse](request, requestOptions)
execute[WatchResponse](
request,
Some(
RequestOptions(
writeTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
readTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
connectTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS))
) + requestOptions
)
)
}

/** Runs all tasks linked to a source, only available for Shopify sources. It will create 1 run per task.
Expand Down Expand Up @@ -1453,7 +1462,16 @@ class IngestionClient(
.withMethod("POST")
.withPath(s"/1/sources/${escape(sourceID)}/discover")
.build()
execute[WatchResponse](request, requestOptions)
execute[WatchResponse](
request,
Some(
RequestOptions(
writeTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
readTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
connectTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS))
) + requestOptions
)
)
}

/** Try a transformation before creating it.
Expand Down Expand Up @@ -1676,7 +1694,16 @@ class IngestionClient(
.withPath(s"/1/sources/validate")
.withBody(sourceCreate)
.build()
execute[WatchResponse](request, requestOptions)
execute[WatchResponse](
request,
Some(
RequestOptions(
writeTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
readTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
connectTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS))
) + requestOptions
)
)
}

/** Validates an update of a source payload to ensure it can be created and that the data source can be reached by
Expand Down Expand Up @@ -1704,7 +1731,16 @@ class IngestionClient(
.withPath(s"/1/sources/${escape(sourceID)}/validate")
.withBody(sourceUpdate)
.build()
execute[WatchResponse](request, requestOptions)
execute[WatchResponse](
request,
Some(
RequestOptions(
writeTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
readTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS)),
connectTimeout = Some(Duration(180000, TimeUnit.MILLISECONDS))
) + requestOptions
)
)
}

}
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/InsightsClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ object InsightsClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(region: Option[String] = None): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/MonitoringClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ object MonitoringClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/PersonalizationClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ object PersonalizationClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(region: String): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/QuerySuggestionsClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ object QuerySuggestionsClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(region: String): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/RecommendClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ object RecommendClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(appId: String): Seq[Host] = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/algoliasearch/api/SearchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ object SearchClient {
)

private def readTimeout(): Duration = {
Duration(5, TimeUnit.SECONDS)
Duration(5000, TimeUnit.MILLISECONDS)
}

private def connectTimeout(): Duration = {
Duration(2, TimeUnit.SECONDS)
Duration(2000, TimeUnit.MILLISECONDS)
}

private def writeTimeout(): Duration = {
Duration(30, TimeUnit.SECONDS)
Duration(30000, TimeUnit.MILLISECONDS)
}

private def hosts(appId: String): Seq[Host] = {
Expand Down
29 changes: 26 additions & 3 deletions src/main/scala/algoliasearch/config/RequestOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@ import scala.concurrent.duration.Duration
* HTTP read timeout
* @param writeTimeout
* HTTP write timeout
* @param connectTimeout
* HTTP connect timeout
*/
case class RequestOptions(
headers: Map[String, String] = Map.empty,
queryParameters: Map[String, String] = Map.empty,
readTimeout: Option[Duration] = None,
writeTimeout: Option[Duration] = None
)
writeTimeout: Option[Duration] = None,
connectTimeout: Option[Duration] = None
) {
def +(other: Option[RequestOptions]): RequestOptions = {
val some = other.getOrElse(return this)
new RequestOptions(
headers = this.headers ++ some.headers,
queryParameters = this.queryParameters ++ some.queryParameters,
readTimeout = some.readTimeout.orElse(this.readTimeout),
writeTimeout = some.writeTimeout.orElse(this.writeTimeout),
connectTimeout = some.connectTimeout.orElse(this.connectTimeout)
)
}
}

object RequestOptions {

Expand All @@ -33,6 +47,7 @@ object RequestOptions {
private val queryParameters: mutable.Map[String, String] = mutable.Map()
private var readTimeout: Option[Duration] = None
private var writeTimeout: Option[Duration] = None
private var connectTimeout: Option[Duration] = None

/** Adds a header to the request.
*/
Expand Down Expand Up @@ -62,14 +77,22 @@ object RequestOptions {
this
}

/** Sets the write timeout for the request.
*/
def withConnectTimeout(connectTimeout: Option[Duration]): Builder = {
this.connectTimeout = connectTimeout
this
}

/** Builds the [[RequestOptions]].
*/
def build(): RequestOptions = {
RequestOptions(
headers = headers.toMap,
queryParameters = queryParameters.toMap,
readTimeout = readTimeout,
writeTimeout = writeTimeout
writeTimeout = writeTimeout,
connectTimeout = connectTimeout
)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/algoliasearch/internal/HttpRequester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private[algoliasearch] class HttpRequester private (
requestOptions.foreach(options => {
options.readTimeout.foreach(timeout => builder.readTimeout(timeout.toMillis, TimeUnit.MILLISECONDS))
options.writeTimeout.foreach(timeout => builder.writeTimeout(timeout.toMillis, TimeUnit.MILLISECONDS))
options.connectTimeout.foreach(timeout => builder.connectTimeout(timeout.toMillis, TimeUnit.MILLISECONDS))
})
builder.build
}
Expand Down

0 comments on commit 6e71ebc

Please sign in to comment.