@@ -961,49 +961,6 @@ def _should_gzip(self, payload: str, enable_gzip: bool = False, gzip_threshold:
961961
962962 return False
963963
964- @staticmethod
965- def _on_error (ex ):
966- logger .error ("unexpected error during batching: %s" , ex )
967-
968- def _to_response (self , data : _BatchItem , delay : datetime .timedelta ):
969- return rx .of (data ).pipe (
970- ops .subscribe_on (self ._write_options .write_scheduler ),
971- # use delay if its specified
972- ops .delay (duetime = delay , scheduler = self ._write_options .write_scheduler ),
973- # invoke http call
974- ops .map (lambda x : self ._http (x , ** x .key .kwargs )),
975- # catch exception to fail batch response
976- ops .catch (handler = lambda exception , source : rx .just (_BatchResponse (exception = exception , data = data ))),
977- )
978-
979- def _on_next (self , response : _BatchResponse ):
980- if response .exception :
981- logger .error ("The batch item wasn't processed successfully because: %s" , response .exception )
982- if self ._error_callback :
983- try :
984- self ._error_callback (response .data .to_key_tuple (), response .data .data , response .exception )
985- except Exception as e :
986- """
987- Unfortunately, because callbacks are user-provided generic code, exceptions can be entirely
988- arbitrary
989-
990- We trap it, log that it occurred and then proceed - there's not much more that we can
991- really do.
992- """
993- logger .error ("The configured error callback threw an exception: %s" , e )
994-
995- else :
996- logger .debug ("The batch item: %s was processed successfully." , response )
997- if self ._success_callback :
998- try :
999- self ._success_callback (response .data .to_key_tuple (), response .data .data )
1000- except Exception as e :
1001- logger .error ("The configured success callback threw an exception: %s" , e )
1002-
1003- def _on_complete (self ):
1004- self ._disposable .dispose ()
1005- logger .debug ("the batching processor was disposed" )
1006-
1007964 def _append_default_tag (self , key , val , record ):
1008965 from influxdb_client_3 .write_client import Point
1009966 if isinstance (record , bytes ) or isinstance (record , str ):
@@ -1088,6 +1045,49 @@ def __del__(self):
10881045 """Close WriteApi."""
10891046 self .close ()
10901047
1048+ @staticmethod
1049+ def _on_error (ex ):
1050+ logger .error ("unexpected error during batching: %s" , ex )
1051+
1052+ def _on_complete (self ):
1053+ self ._disposable .dispose ()
1054+ logger .debug ("the batching processor was disposed" )
1055+
1056+ def _to_response (self , data : _BatchItem , delay : datetime .timedelta ):
1057+ return rx .of (data ).pipe (
1058+ ops .subscribe_on (self ._write_options .write_scheduler ),
1059+ # use delay if its specified
1060+ ops .delay (duetime = delay , scheduler = self ._write_options .write_scheduler ),
1061+ # invoke http call
1062+ ops .map (lambda x : self ._http (x , ** x .key .kwargs )),
1063+ # catch exception to fail batch response
1064+ ops .catch (handler = lambda exception , source : rx .just (_BatchResponse (exception = exception , data = data ))),
1065+ )
1066+
1067+ def _on_next (self , response : _BatchResponse ):
1068+ if response .exception :
1069+ logger .error ("The batch item wasn't processed successfully because: %s" , response .exception )
1070+ if self ._error_callback :
1071+ try :
1072+ self ._error_callback (response .data .to_key_tuple (), response .data .data , response .exception )
1073+ except Exception as e :
1074+ """
1075+ Unfortunately, because callbacks are user-provided generic code, exceptions can be entirely
1076+ arbitrary
1077+
1078+ We trap it, log that it occurred and then proceed - there's not much more that we can
1079+ really do.
1080+ """
1081+ logger .error ("The configured error callback threw an exception: %s" , e )
1082+
1083+ else :
1084+ logger .debug ("The batch item: %s was processed successfully." , response )
1085+ if self ._success_callback :
1086+ try :
1087+ self ._success_callback (response .data .to_key_tuple (), response .data .data )
1088+ except Exception as e :
1089+ logger .error ("The configured success callback threw an exception: %s" , e )
1090+
10911091 def __getstate__ (self ):
10921092 """Return a dict of attributes that you want to pickle."""
10931093 state = self .__dict__ .copy ()
0 commit comments