Skip to content

Commit d584301

Browse files
committed
chore: using _request_timeout write kwargs in write calls.
1 parent cdd6e1e commit d584301

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

influxdb_client_3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ def write(self, record=None, database=None, **kwargs):
377377
:type database: str
378378
:param kwargs: Additional arguments to pass to the write API.
379379
"""
380+
print("DEBUG InfluxDBClient3.write")
381+
print(f"DEBUG kwargs {kwargs} ")
380382
if database is None:
381383
database = self._database
382384

influxdb_client_3/write_client/client/write_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ def write(self, bucket: str, org: str = None,
378378
data_frame.index = pd.to_datetime(data_frame.index, unit='s')
379379
380380
""" # noqa: E501
381+
print("DEBUG WriteApi.write")
382+
print(f"DEBUG kwargs {kwargs}")
381383
org = get_org_query_param(org=org, client=self._influxdb_client)
382384

383385
self._append_default_tags(record)
@@ -398,7 +400,7 @@ def write(self, bucket: str, org: str = None,
398400

399401
def write_payload(payload):
400402
final_string = b'\n'.join(payload[1])
401-
return self._post_write(_async_req, bucket, org, final_string, payload[0], no_sync)
403+
return self._post_write(_async_req, bucket, org, final_string, payload[0], no_sync, **kwargs)
402404

403405
results = list(map(write_payload, payloads.items()))
404406
if not _async_req:
@@ -527,6 +529,7 @@ def _write_batching(self, bucket, org, data,
527529

528530
def _http(self, batch_item: _BatchItem):
529531
logger.debug("Write time series data into InfluxDB: %s", batch_item)
532+
print("DEBUG _http")
530533

531534
if self._retry_callback:
532535
def _retry_callback_delegate(exception):
@@ -546,6 +549,8 @@ def _retry_callback_delegate(exception):
546549
return _BatchResponse(data=batch_item)
547550

548551
def _post_write(self, _async_req, bucket, org, body, precision, no_sync, **kwargs):
552+
print("DEBUG WriteApi._post_write")
553+
print(f"DEBUG kwargs {kwargs} ")
549554
return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
550555
no_sync=no_sync,
551556
async_req=_async_req,

influxdb_client_3/write_client/service/write_service.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ def post_write(self, org, bucket, body, **kwargs): # noqa: E501,D401,D403
4141
If the method is called asynchronously,
4242
returns the request thread.
4343
""" # noqa: E501
44+
45+
print("DEBUG WriteService.post_write")
46+
print(f"DEBUG kwargs {kwargs}")
47+
4448
kwargs['_return_http_data_only'] = True
4549
if kwargs.get('async_req'):
4650
thread = self.post_write_with_http_info(org, bucket, body, **kwargs) # noqa: E501
47-
# return self.post_write_with_http_info(org, bucket, body, **kwargs) # noqa: E501
4851
return thread
4952
else:
5053
(data) = self.post_write_with_http_info(org, bucket, body, **kwargs) # noqa: E501
@@ -136,7 +139,8 @@ def post_write_with_http_info(self, org, bucket, body, **kwargs): # noqa: E501,
136139
If the method is called asynchronously,
137140
returns the request thread.
138141
""" # noqa: E501
139-
print("WriteService.post_write_with_http_info()")
142+
print("DEBUG WriteService.post_write_with_http_info()")
143+
print(f"DEBUG kwargs {kwargs}")
140144
# noqa: E501
141145
local_var_params, path, path_params, query_params, header_params, body_params = \
142146
self._post_write_prepare(org, bucket, body, **kwargs) # noqa: E501

tests/test_influxdb_client_3_integration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,32 @@ def retry_cb(args, data, excp):
387387
self.assertIsInstance(ErrorResult["rx"], MaxRetryError)
388388
self.assertIsInstance(ErrorResult["rx"].reason, Url3TimeoutError)
389389

390+
def test_write_timeout_argument(self):
391+
with self.assertRaises(Url3TimeoutError):
392+
localClient = InfluxDBClient3(
393+
host=self.host,
394+
database=self.database,
395+
token=self.token,
396+
write_client_options=write_client_options(
397+
# error_callback=set_error_result,
398+
# retry_callback=retry_cb,
399+
# write_options=WriteOptions(
400+
# max_retry_time=10000,
401+
# max_retry_delay=0,
402+
# retry_interval=0,
403+
# timeout=20,
404+
# max_retries=0,
405+
# batch_size=1,
406+
# )
407+
)
408+
)
409+
410+
print(f"DEBUG client.write_options {localClient._write_client_options['write_options'].__dict__}")
411+
412+
lp = "test_write_timeout,location=harfa fVal=3.14,iVal=42i"
413+
# TODO investigate how the kwarg below can work with WriteType.batching...
414+
localClient.write(lp, _request_timeout=1)
415+
390416
@pytest.mark.skip(reason="flaky in CircleCI - server often responds in less than 1 millisecond.")
391417
def test_query_timeout(self):
392418
localClient = InfluxDBClient3(

tests/test_write_local_server.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,19 @@ def test_write_with_write_timeout(self, httpserver: HTTPServer):
167167
),
168168
enable_gzip=True
169169
).write(self.SAMPLE_RECORD)
170+
171+
def test_write_with_timeout_arg(self, httpserver: HTTPServer):
172+
self.set_response_status(httpserver, 200)
173+
174+
with pytest.raises(urllib3_TimeoutError):
175+
InfluxDBClient3(
176+
host=(httpserver.url_for("/")), org="ORG", database="DB", token="TOKEN",
177+
write_client_options=write_client_options(
178+
write_options=WriteOptions(
179+
write_type=WriteType.synchronous,
180+
write_precision=WritePrecision.US,
181+
no_sync=True,
182+
)
183+
),
184+
enable_gzip=True
185+
).write(self.SAMPLE_RECORD, _request_timeout=1)

0 commit comments

Comments
 (0)