@@ -248,16 +248,15 @@ def has_limit(self):
248
248
return not self .__no_limit
249
249
250
250
def set_limit (self , rate_limit , percentage = 0 ):
251
- self .__rate_limit_dict = {}
252
251
rate_configs = rate_limit .split (";" )
253
252
if "," in rate_limit :
254
253
rate_configs = rate_limit .split ("," )
255
254
for rate in rate_configs :
256
255
if rate == "" :
257
256
continue
258
257
rate = rate .split (":" )
259
- self .__rate_limit_dict [int (rate [1 ])] = {"counter" : self .__rate_limit_dict [ int (rate [1 ])][ 'counter' ] ,
260
- "start" : self .__rate_limit_dict [ int (rate [1 ])][ 'start' ] ,
258
+ self .__rate_limit_dict [int (rate [1 ])] = {"counter" : self .__rate_limit_dict . get ( int (rate [1 ]), {}). get ( 'counter' , 0 ) ,
259
+ "start" : self .__rate_limit_dict . get ( int (rate [1 ]), {}). get ( 'start' , int ( time ())) ,
261
260
"limit" : int (rate [0 ]) * percentage / 100 }
262
261
263
262
@staticmethod
@@ -653,12 +652,12 @@ def request_service_configuration(self, callback):
653
652
self .send_rpc_call ("getSessionLimits" , {}, callback )
654
653
655
654
def on_service_configuration (self , _ , service_config , * args , ** kwargs ):
656
- if not isinstance (service_config , dict ) or 'rateLimits ' not in service_config :
655
+ if not isinstance (service_config , dict ) or 'rateLimit ' not in service_config :
657
656
log .warning ("Cannot retrieve service configuration, session will use default configuration." )
658
657
log .debug ("Received the following response: %r" , service_config )
659
658
return
660
- if service_config .get ("rateLimits " ):
661
- rate_limits_config = service_config .get ("rateLimits " )
659
+ if service_config .get ("rateLimit " ):
660
+ rate_limits_config = service_config .get ("rateLimit " )
662
661
663
662
if rate_limits_config .get ('messages' ):
664
663
self ._messages_rate_limit .set_limit (rate_limits_config .get ('messages' ), percentage = 80 )
@@ -670,6 +669,8 @@ def on_service_configuration(self, _, service_config, *args, **kwargs):
670
669
self .max_inflight_messages_set (int (service_config .get ('maxInflightMessages' )))
671
670
if service_config .get ('maxPayloadSize' ):
672
671
self .max_payload_size = int (service_config .get ('maxPayloadSize' ))
672
+ log .info ("Service configuration was successfully retrieved and applied." )
673
+ log .info ("Current limits: %r" , service_config )
673
674
674
675
def set_server_side_rpc_request_handler (self , handler ):
675
676
"""Set the callback that will be called when a server-side RPC is received."""
@@ -922,7 +923,7 @@ def request_attributes(self, client_keys=None, shared_keys=None, callback=None):
922
923
tmp = tmp [:len (tmp ) - 1 ]
923
924
msg .update ({"sharedKeys" : tmp })
924
925
925
- ts_in_millis = int (time () * 1000 )
926
+ ts_in_millis = int (time ())
926
927
927
928
attr_request_number = self ._add_attr_request_callback (callback )
928
929
@@ -944,7 +945,7 @@ def _add_attr_request_callback(self, callback):
944
945
945
946
def __timeout_check (self ):
946
947
while not self .stopped :
947
- current_ts_in_millis = int (time () * 1000 )
948
+ current_ts_in_millis = int (time ())
948
949
for (attr_request_number , ts ) in tuple (self .__attrs_request_timeout .items ()):
949
950
if current_ts_in_millis < ts :
950
951
continue
0 commit comments