@@ -164,10 +164,11 @@ def add_default_tag(self, key, value) -> None:
164164
165165
166166class _BatchItemKey (object ):
167- def __init__ (self , bucket , org , precision = DEFAULT_WRITE_PRECISION ) -> None :
167+ def __init__ (self , bucket , org , precision = DEFAULT_WRITE_PRECISION , ** kwargs ) -> None :
168168 self .bucket = bucket
169169 self .org = org
170170 self .precision = precision
171+ self .kwargs = kwargs
171172 pass
172173
173174 def __hash__ (self ) -> int :
@@ -178,8 +179,8 @@ def __eq__(self, o: object) -> bool:
178179 and self .bucket == o .bucket and self .org == o .org and self .precision == o .precision
179180
180181 def __str__ (self ) -> str :
181- return '_BatchItemKey[bucket:\' {}\' , org:\' {}\' , precision:\' {}\' ]' \
182- .format (str (self .bucket ), str (self .org ), str (self .precision ))
182+ return '_BatchItemKey[bucket:\' {}\' , org:\' {}\' , precision:\' {}\' , kwargs: \' {} \' ]' \
183+ .format (str (self .bucket ), str (self .org ), str (self .precision ), str ( self . kwargs ) )
183184
184185
185186class _BatchItem (object ):
@@ -378,8 +379,6 @@ def write(self, bucket: str, org: str = None,
378379 data_frame.index = pd.to_datetime(data_frame.index, unit='s')
379380
380381 """ # noqa: E501
381- print ("DEBUG WriteApi.write" )
382- print (f"DEBUG kwargs { kwargs } " )
383382 org = get_org_query_param (org = org , client = self ._influxdb_client )
384383
385384 self ._append_default_tags (record )
@@ -477,7 +476,7 @@ def _write_batching(self, bucket, org, data,
477476 precision = self ._write_options .write_precision
478477
479478 if isinstance (data , bytes ):
480- _key = _BatchItemKey (bucket , org , precision )
479+ _key = _BatchItemKey (bucket , org , precision , ** kwargs )
481480 self ._subject .on_next (_BatchItem (key = _key , data = data ))
482481
483482 elif isinstance (data , str ):
@@ -527,9 +526,8 @@ def _write_batching(self, bucket, org, data,
527526
528527 return None
529528
530- def _http (self , batch_item : _BatchItem ):
529+ def _http (self , batch_item : _BatchItem , ** kwargs ):
531530 logger .debug ("Write time series data into InfluxDB: %s" , batch_item )
532- print ("DEBUG _http" )
533531
534532 if self ._retry_callback :
535533 def _retry_callback_delegate (exception ):
@@ -542,29 +540,28 @@ def _retry_callback_delegate(exception):
542540 retry = self ._write_options .to_retry_strategy (retry_callback = _retry_callback_delegate )
543541
544542 self ._post_write (False , batch_item .key .bucket , batch_item .key .org , batch_item .data ,
545- batch_item .key .precision , no_sync , urlopen_kw = {'retries' : retry })
543+ batch_item .key .precision , no_sync , urlopen_kw = {'retries' : retry }, ** kwargs )
546544
547545 logger .debug ("Write request finished %s" , batch_item )
548546
549547 return _BatchResponse (data = batch_item )
550548
551549 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 } " )
554- return self ._write_service .post_write (org = org , bucket = bucket , body = body , precision = precision ,
550+ return self ._write_service .post_write (org = org , bucket = bucket , body = body , precision = precision ,
555551 no_sync = no_sync ,
556552 async_req = _async_req ,
557553 content_type = "text/plain; charset=utf-8" ,
558554 ** kwargs )
559555
556+
560557 def _to_response (self , data : _BatchItem , delay : timedelta ):
561558
562559 return rx .of (data ).pipe (
563560 ops .subscribe_on (self ._write_options .write_scheduler ),
564561 # use delay if its specified
565562 ops .delay (duetime = delay , scheduler = self ._write_options .write_scheduler ),
566563 # invoke http call
567- ops .map (lambda x : self ._http (x )),
564+ ops .map (lambda x : self ._http (x , ** x . key . kwargs )),
568565 # catch exception to fail batch response
569566 ops .catch (handler = lambda exception , source : rx .just (_BatchResponse (exception = exception , data = data ))),
570567 )
0 commit comments