33import grpc
44import web3
55
6- from snet .sdk .service_client import ServiceClient
76from snet .sdk .utils .utils import RESOURCES_PATH , add_to_path
87
98
109class ConcurrencyManager :
11- def __init__ (self , concurrent_calls : int ):
10+ def __init__ (self , concurrent_calls : int = 1 ):
1211 self .__concurrent_calls : int = concurrent_calls
1312 self .__token : str = ''
1413 self .__planned_amount : int = 0
@@ -18,14 +17,18 @@ def __init__(self, concurrent_calls: int):
1817 def concurrent_calls (self ) -> int :
1918 return self .__concurrent_calls
2019
20+ @concurrent_calls .setter
21+ def concurrent_calls (self , concurrent_calls : int ):
22+ self .__concurrent_calls = concurrent_calls
23+
2124 def get_token (self , service_client , channel , service_call_price ):
2225 if len (self .__token ) == 0 :
2326 self .__token = self .__get_token (service_client , channel , service_call_price )
2427 elif self .__used_amount >= self .__planned_amount :
2528 self .__token = self .__get_token (service_client , channel , service_call_price , new_token = True )
2629 return self .__token
2730
28- def __get_token (self , service_client : ServiceClient , channel , service_call_price , new_token = False ):
31+ def __get_token (self , service_client , channel , service_call_price , new_token = False ):
2932 if not new_token :
3033 amount = channel .state ["last_signed_amount" ]
3134 if amount != 0 :
@@ -47,13 +50,13 @@ def __get_token(self, service_client: ServiceClient, channel, service_call_price
4750 self .__planned_amount = token_reply .planned_amount
4851 return token_reply .token
4952
50- def __get_stub_for_get_token (self , service_client : ServiceClient ):
53+ def __get_stub_for_get_token (self , service_client ):
5154 grpc_channel = service_client .get_grpc_base_channel ()
5255 with add_to_path (str (RESOURCES_PATH .joinpath ("proto" ))):
5356 token_service_pb2_grpc = importlib .import_module ("token_service_pb2_grpc" )
5457 return token_service_pb2_grpc .TokenServiceStub (grpc_channel )
5558
56- def __get_token_for_amount (self , service_client : ServiceClient , channel , amount ):
59+ def __get_token_for_amount (self , service_client , channel , amount ):
5760 nonce = channel .state ["nonce" ]
5861 stub = self .__get_stub_for_get_token (service_client )
5962 with add_to_path (str (RESOURCES_PATH .joinpath ("proto" ))):
0 commit comments