11import abc
2+ import math
3+ import time
24
35from typing import List , Union
46
57from algoliasearch .exceptions import RequestException
6- from algoliasearch .helpers import get_items
8+ from algoliasearch .helpers import get_items , sleep_for
79from algoliasearch .http .request_options import RequestOptions
810
911try :
@@ -98,13 +100,20 @@ def __init__(self, client, raw_response):
98100 def wait (self ):
99101 # type: () -> AddApiKeyResponse
100102
103+ retries_count = 1
104+
101105 while not self ._done :
102106 try :
103107 self ._client ._sync ().get_api_key (self .raw_response ['key' ])
104108 self ._done = True
105109 except RequestException as e :
106110 if e .status_code != 404 :
107111 raise e
112+ retries_count += 1
113+ sleep_for (
114+ retries_count ,
115+ self ._client ._config .wait_task_time_before_retry
116+ )
108117
109118 return self
110119
@@ -127,14 +136,22 @@ def __init__(self, client, raw_response, request_options):
127136 def wait (self ):
128137 # type: () -> UpdateApiKeyResponse
129138
139+ retries_count = 1
140+
130141 while not self ._done :
131142 api_key = self ._client ._sync ().get_api_key (
132143 self .raw_response ['key' ],
133144 self ._request_options
134145 )
135146
136- if self ._have_changed (api_key ):
137- break
147+ self ._done = self ._have_changed (api_key )
148+
149+ if not self ._done :
150+ retries_count += 1
151+ sleep_for (
152+ retries_count ,
153+ self ._client ._config .wait_task_time_before_retry
154+ )
138155
139156 return self
140157
@@ -171,12 +188,21 @@ def __init__(self, client, raw_response, key):
171188 def wait (self ):
172189 # type: () -> DeleteApiKeyResponse
173190
191+ retries_count = 1
192+
174193 while not self ._done :
175194 try :
176195 self ._client ._sync ().get_api_key (self ._key )
177196 except RequestException as e :
178197 self ._done = e .status_code == 404
179198
199+ if not self ._done :
200+ retries_count += 1
201+ sleep_for (
202+ retries_count ,
203+ self ._client ._config .wait_task_time_before_retry
204+ )
205+
180206 return self
181207
182208 def __getitem__ (self , key ):
@@ -198,13 +224,20 @@ def __init__(self, client, raw_response, key):
198224 def wait (self ):
199225 # type: () -> RestoreApiKeyResponse
200226
227+ retries_count = 1
228+
201229 while not self ._done :
202230 try :
203231 self ._client ._sync ().get_api_key (self ._key )
204232 self ._done = True
205233 except RequestException as e :
206234 if e .status_code != 404 :
207235 raise e
236+ retries_count += 1
237+ sleep_for (
238+ retries_count ,
239+ self ._client ._config .wait_task_time_before_retry
240+ )
208241
209242 return self
210243
0 commit comments