2525from influxdb_client_3 .write_client .rest import _UTF_8_encoding
2626
2727DEFAULT_WRITE_NO_SYNC = False
28+ DEFAULT_WRITE_TIMEOUT = 10_000
2829
2930logger = logging .getLogger ('influxdb_client_3.write_client.client.write_api' )
3031
@@ -45,6 +46,7 @@ class DefaultWriteOptions(Enum):
4546 write_type = WriteType .synchronous
4647 write_precision = DEFAULT_WRITE_PRECISION
4748 no_sync = DEFAULT_WRITE_NO_SYNC
49+ timeout = DEFAULT_WRITE_TIMEOUT
4850
4951
5052class WriteOptions (object ):
@@ -61,6 +63,7 @@ def __init__(self, write_type: WriteType = WriteType.batching,
6163 max_close_wait = 300_000 ,
6264 write_precision = DEFAULT_WRITE_PRECISION ,
6365 no_sync = DEFAULT_WRITE_NO_SYNC ,
66+ timeout = DEFAULT_WRITE_TIMEOUT ,
6467 write_scheduler = ThreadPoolScheduler (max_workers = 1 )) -> None :
6568 """
6669 Create write api configuration.
@@ -93,6 +96,7 @@ def __init__(self, write_type: WriteType = WriteType.batching,
9396 self .write_scheduler = write_scheduler
9497 self .max_close_wait = max_close_wait
9598 self .write_precision = write_precision
99+ self .timeout = timeout
96100 self .no_sync = no_sync
97101
98102 def to_retry_strategy (self , ** kwargs ):
@@ -268,6 +272,8 @@ def __init__(self,
268272 # Define Subject that listen incoming data and produces writes into InfluxDB
269273 self ._subject = Subject ()
270274
275+ print (f"DEBUG batching write with subject { self ._subject } " )
276+
271277 self ._disposable = self ._subject .pipe (
272278 # Split incoming data to windows by batch_size or flush_interval
273279 ops .window_with_time_or_count (count = write_options .batch_size ,
@@ -372,6 +378,7 @@ def write(self, bucket: str, org: str = None,
372378
373379 """ # noqa: E501
374380 org = get_org_query_param (org = org , client = self ._influxdb_client )
381+ print ("DEBUG WriteApi.write()" )
375382
376383 self ._append_default_tags (record )
377384
@@ -390,13 +397,21 @@ def write(self, bucket: str, org: str = None,
390397 _async_req = True if self ._write_options .write_type == WriteType .asynchronous else False
391398
392399 def write_payload (payload ):
400+ print ("DEBUG WriteApi.write_payload()" )
393401 final_string = b'\n ' .join (payload [1 ])
394- return self ._post_write (_async_req , bucket , org , final_string , payload [0 ], no_sync )
402+ result = 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)
404+ print (f" DEBUG write_payload() result { result } " )
405+ return result
395406
396407 results = list (map (write_payload , payloads .items ()))
408+ print (f" DEBUG WriteApi.write() results { results } " )
397409 if not _async_req :
410+ print (f" --->DEBUG not async_request" )
398411 return None
399412 elif len (results ) == 1 :
413+ # TODO if results contains error or exception ensure handled
414+ print (f" --->DEBUG async_request() results { results [0 ]} " )
400415 return results [0 ]
401416 return results
402417
@@ -464,11 +479,13 @@ def __del__(self):
464479 def _write_batching (self , bucket , org , data ,
465480 precision = None ,
466481 ** kwargs ):
482+ print ("DEBUG _write_batching()" )
467483 if precision is None :
468484 precision = self ._write_options .write_precision
469485
470486 if isinstance (data , bytes ):
471487 _key = _BatchItemKey (bucket , org , precision )
488+ print (f" DEBUG _write_batching() data bytes { _key } " )
472489 self ._subject .on_next (_BatchItem (key = _key , data = data ))
473490
474491 elif isinstance (data , str ):
@@ -520,6 +537,8 @@ def _write_batching(self, bucket, org, data,
520537
521538 def _http (self , batch_item : _BatchItem ):
522539
540+ print ("DEBUG _http()" )
541+
523542 logger .debug ("Write time series data into InfluxDB: %s" , batch_item )
524543
525544 if self ._retry_callback :
@@ -540,6 +559,7 @@ def _retry_callback_delegate(exception):
540559 return _BatchResponse (data = batch_item )
541560
542561 def _post_write (self , _async_req , bucket , org , body , precision , no_sync , ** kwargs ):
562+ print ("DEBUG write_api._post_write()" )
543563
544564 return self ._write_service .post_write (org = org , bucket = bucket , body = body , precision = precision ,
545565 no_sync = no_sync ,
@@ -549,6 +569,8 @@ def _post_write(self, _async_req, bucket, org, body, precision, no_sync, **kwarg
549569
550570 def _to_response (self , data : _BatchItem , delay : timedelta ):
551571
572+ print ("DEBUG _to_response()" )
573+
552574 return rx .of (data ).pipe (
553575 ops .subscribe_on (self ._write_options .write_scheduler ),
554576 # use delay if its specified
0 commit comments