From 679a8cdb60d64bd07f515ac2428ea77505a02119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 18 Dec 2024 11:04:20 +0100 Subject: [PATCH] fix(specs): endpoint level timeout for ingestion (#4251) --- .../algoliasearch/http/request_options.py | 7 ++++--- specs/ingestion/paths/sources/discover.yml | 4 ++++ specs/ingestion/paths/sources/validate.yml | 4 ++++ specs/ingestion/paths/sources/validateID.yml | 4 ++++ specs/ingestion/paths/tasks/v2/pushTask.yml | 4 ++++ templates/javascript/clients/api-single.mustache | 11 +++++++++++ templates/python/api.mustache | 7 +++++++ templates/ruby/api.mustache | 5 ++++- 8 files changed, 42 insertions(+), 4 deletions(-) diff --git a/clients/algoliasearch-client-python/algoliasearch/http/request_options.py b/clients/algoliasearch-client-python/algoliasearch/http/request_options.py index e220831628..7d87610f0b 100644 --- a/clients/algoliasearch-client-python/algoliasearch/http/request_options.py +++ b/clients/algoliasearch-client-python/algoliasearch/http/request_options.py @@ -58,6 +58,7 @@ def merge( query_parameters: Optional[Dict[str, Any]] = None, headers: Optional[Dict[str, str]] = None, data: Optional[str] = None, + timeouts: Dict[str, int] = {}, user_request_options: Optional[Union[Self, Dict[str, Any]]] = None, ) -> Self: """ @@ -74,9 +75,9 @@ def merge( "headers": headers, "query_parameters": query_parameters, "timeouts": { - "read": self._config.read_timeout, - "write": self._config.write_timeout, - "connect": self._config.connect_timeout, + "read": timeouts.get("read", self._config.read_timeout), + "write": timeouts.get("write", self._config.write_timeout), + "connect": timeouts.get("connect", self._config.connect_timeout), }, "data": data, } diff --git a/specs/ingestion/paths/sources/discover.yml b/specs/ingestion/paths/sources/discover.yml index 4e1cc387ed..f0f05ff043 100644 --- a/specs/ingestion/paths/sources/discover.yml +++ b/specs/ingestion/paths/sources/discover.yml @@ -10,6 +10,10 @@ post: - addObject - deleteIndex - editSettings + x-timeouts: + connect: 180000 + read: 180000 + write: 180000 parameters: - $ref: '../../common/parameters.yml#/pathSourceID' responses: diff --git a/specs/ingestion/paths/sources/validate.yml b/specs/ingestion/paths/sources/validate.yml index 447f65b1a0..b749c72155 100644 --- a/specs/ingestion/paths/sources/validate.yml +++ b/specs/ingestion/paths/sources/validate.yml @@ -9,6 +9,10 @@ post: - addObject - deleteIndex - editSettings + x-timeouts: + connect: 180000 + read: 180000 + write: 180000 requestBody: description: '' content: diff --git a/specs/ingestion/paths/sources/validateID.yml b/specs/ingestion/paths/sources/validateID.yml index f40028bc4f..079e43eefb 100644 --- a/specs/ingestion/paths/sources/validateID.yml +++ b/specs/ingestion/paths/sources/validateID.yml @@ -9,6 +9,10 @@ post: - addObject - deleteIndex - editSettings + x-timeouts: + connect: 180000 + read: 180000 + write: 180000 parameters: - $ref: '../../common/parameters.yml#/pathSourceID' requestBody: diff --git a/specs/ingestion/paths/tasks/v2/pushTask.yml b/specs/ingestion/paths/tasks/v2/pushTask.yml index b43c64d5d6..b689a9721d 100644 --- a/specs/ingestion/paths/tasks/v2/pushTask.yml +++ b/specs/ingestion/paths/tasks/v2/pushTask.yml @@ -8,6 +8,10 @@ post: - addObject - deleteIndex - editSettings + x-timeouts: + connect: 180000 + read: 180000 + write: 180000 parameters: - $ref: '../../../common/parameters.yml#/pathTaskID' - name: watch diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index 1cbafd7692..66d74e8651 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -159,6 +159,17 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ {{/vendorExtensions}} }; + {{#vendorExtensions.x-timeouts}} + requestOptions = { + timeouts: { + connect: {{connect}}, + read: {{read}}, + write: {{write}}, + ...requestOptions?.timeouts, + } + } + {{/vendorExtensions.x-timeouts}} + return transporter.request(request, requestOptions); }, diff --git a/templates/python/api.mustache b/templates/python/api.mustache index f483a8e4d5..a832dfddf6 100644 --- a/templates/python/api.mustache +++ b/templates/python/api.mustache @@ -180,6 +180,13 @@ class {{classname}}{{#isSyncClient}}Sync{{/isSyncClient}}: {{#queryParams.0}}query_parameters=_query_parameters,{{/queryParams.0}} {{#headerParams.0}}headers=_headers,{{/headerParams.0}} {{#bodyParam}}data=dumps(body_serializer(_data)),{{/bodyParam}} + {{#vendorExtensions.x-timeouts}} + timeouts={ + "read": {{read}}, + "write": {{write}}, + "connect": {{connect}}, + }, + {{/vendorExtensions.x-timeouts}} user_request_options=request_options, ), {{#vendorExtensions}} diff --git a/templates/ruby/api.mustache b/templates/ruby/api.mustache index 6bdfbe5954..971b44e499 100644 --- a/templates/ruby/api.mustache +++ b/templates/ruby/api.mustache @@ -138,6 +138,9 @@ module {{moduleName}} {{/headerParams}} header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? {{/vendorExtensions}} + {{#vendorExtensions.x-timeouts}} + request_options[:timeout] ||= {{#vendorExtensions.x-use-read-transporter}}{{vendorExtensions.x-timeouts.read}}{{/vendorExtensions.x-use-read-transporter}} {{^vendorExtensions.x-use-read-transporter}}{{vendorExtensions.x-timeouts.write}}{{/vendorExtensions.x-use-read-transporter}} + {{/vendorExtensions.x-timeouts}} post_body = request_options[:debug_body]{{#bodyParam}} || @api_client.object_to_http_body({{{paramName}}}){{/bodyParam}} @@ -187,4 +190,4 @@ module {{moduleName}} {{/isSearchClient}} end {{/operations}} -end +end \ No newline at end of file