Skip to content

Commit 7d59f9b

Browse files
committed
adding dev-v0.12.10 tag to this commit to ensure building
1 parent 01e7e43 commit 7d59f9b

File tree

2 files changed

+82
-24
lines changed

2 files changed

+82
-24
lines changed

html/supertokens_python/constants.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
5353
&#34;2.19&#34;,
5454
&#34;2.20&#34;,
5555
]
56-
VERSION = &#34;0.12.9&#34;
56+
VERSION = &#34;0.12.10&#34;
5757
TELEMETRY = &#34;/telemetry&#34;
5858
USER_COUNT = &#34;/users/count&#34;
5959
USER_DELETE = &#34;/user/remove&#34;
@@ -66,7 +66,8 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
6666
FDI_KEY_HEADER = &#34;fdi-version&#34;
6767
API_VERSION = &#34;/apiversion&#34;
6868
API_VERSION_HEADER = &#34;cdi-version&#34;
69-
DASHBOARD_VERSION = &#34;0.6&#34;</code></pre>
69+
DASHBOARD_VERSION = &#34;0.6&#34;
70+
RATE_LIMIT_STATUS_CODE = 429</code></pre>
7071
</details>
7172
</section>
7273
<section>

html/supertokens_python/querier.html

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
4141
# under the License.
4242
from __future__ import annotations
4343

44+
import asyncio
45+
4446
from json import JSONDecodeError
4547
from os import environ
46-
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict
48+
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Optional
4749

4850
from httpx import AsyncClient, ConnectTimeout, NetworkError, Response
4951

@@ -53,6 +55,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
5355
API_VERSION_HEADER,
5456
RID_KEY_HEADER,
5557
SUPPORTED_CDI_VERSIONS,
58+
RATE_LIMIT_STATUS_CODE,
5659
)
5760
from .normalised_url_path import NormalisedURLPath
5861

@@ -70,7 +73,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
7073
__init_called = False
7174
__hosts: List[Host] = []
7275
__api_key: Union[None, str] = None
73-
__api_version = None
76+
api_version = None
7477
__last_tried_index: int = 0
7578
__hosts_alive_for_testing: Set[str] = set()
7679

@@ -97,8 +100,8 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
97100
return Querier.__hosts_alive_for_testing
98101

99102
async def get_api_version(self):
100-
if Querier.__api_version is not None:
101-
return Querier.__api_version
103+
if Querier.api_version is not None:
104+
return Querier.api_version
102105

103106
ProcessState.get_instance().add_state(
104107
AllowedProcessStates.CALLING_SERVICE_IN_GET_API_VERSION
@@ -124,8 +127,8 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
124127
&#34;to find the right versions&#34;
125128
)
126129

127-
Querier.__api_version = api_version
128-
return Querier.__api_version
130+
Querier.api_version = api_version
131+
return Querier.api_version
129132

130133
@staticmethod
131134
def get_instance(rid_to_core: Union[str, None] = None):
@@ -141,7 +144,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
141144
Querier.__init_called = True
142145
Querier.__hosts = hosts
143146
Querier.__api_key = api_key
144-
Querier.__api_version = None
147+
Querier.api_version = None
145148
Querier.__last_tried_index = 0
146149
Querier.__hosts_alive_for_testing = set()
147150

@@ -231,6 +234,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
231234
method: str,
232235
http_function: Callable[[str], Awaitable[Response]],
233236
no_of_tries: int,
237+
retry_info_map: Optional[Dict[str, int]] = None,
234238
) -&gt; Any:
235239
if no_of_tries == 0:
236240
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
@@ -247,6 +251,14 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
247251
Querier.__last_tried_index %= len(self.__hosts)
248252
url = current_host + path.get_as_string_dangerous()
249253

254+
max_retries = 5
255+
256+
if retry_info_map is None:
257+
retry_info_map = {}
258+
259+
if retry_info_map.get(url) is None:
260+
retry_info_map[url] = max_retries
261+
250262
ProcessState.get_instance().add_state(
251263
AllowedProcessStates.CALLING_SERVICE_IN_REQUEST_HELPER
252264
)
@@ -256,6 +268,20 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
256268
):
257269
Querier.__hosts_alive_for_testing.add(current_host)
258270

271+
if response.status_code == RATE_LIMIT_STATUS_CODE:
272+
retries_left = retry_info_map[url]
273+
274+
if retries_left &gt; 0:
275+
retry_info_map[url] = retries_left - 1
276+
277+
attempts_made = max_retries - retries_left
278+
delay = (10 + attempts_made * 250) / 1000
279+
280+
await asyncio.sleep(delay)
281+
return await self.__send_request_helper(
282+
path, method, http_function, no_of_tries, retry_info_map
283+
)
284+
259285
if is_4xx_error(response.status_code) or is_5xx_error(response.status_code): # type: ignore
260286
raise_general_exception(
261287
&#34;SuperTokens core threw an error for a &#34;
@@ -273,9 +299,9 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
273299
except JSONDecodeError:
274300
return response.text
275301

276-
except (ConnectionError, NetworkError, ConnectTimeout):
302+
except (ConnectionError, NetworkError, ConnectTimeout) as _:
277303
return await self.__send_request_helper(
278-
path, method, http_function, no_of_tries - 1
304+
path, method, http_function, no_of_tries - 1, retry_info_map
279305
)
280306
except Exception as e:
281307
raise_general_exception(e)</code></pre>
@@ -304,7 +330,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
304330
__init_called = False
305331
__hosts: List[Host] = []
306332
__api_key: Union[None, str] = None
307-
__api_version = None
333+
api_version = None
308334
__last_tried_index: int = 0
309335
__hosts_alive_for_testing: Set[str] = set()
310336

@@ -331,8 +357,8 @@ <h2 class="section-title" id="header-classes">Classes</h2>
331357
return Querier.__hosts_alive_for_testing
332358

333359
async def get_api_version(self):
334-
if Querier.__api_version is not None:
335-
return Querier.__api_version
360+
if Querier.api_version is not None:
361+
return Querier.api_version
336362

337363
ProcessState.get_instance().add_state(
338364
AllowedProcessStates.CALLING_SERVICE_IN_GET_API_VERSION
@@ -358,8 +384,8 @@ <h2 class="section-title" id="header-classes">Classes</h2>
358384
&#34;to find the right versions&#34;
359385
)
360386

361-
Querier.__api_version = api_version
362-
return Querier.__api_version
387+
Querier.api_version = api_version
388+
return Querier.api_version
363389

364390
@staticmethod
365391
def get_instance(rid_to_core: Union[str, None] = None):
@@ -375,7 +401,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
375401
Querier.__init_called = True
376402
Querier.__hosts = hosts
377403
Querier.__api_key = api_key
378-
Querier.__api_version = None
404+
Querier.api_version = None
379405
Querier.__last_tried_index = 0
380406
Querier.__hosts_alive_for_testing = set()
381407

@@ -465,6 +491,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
465491
method: str,
466492
http_function: Callable[[str], Awaitable[Response]],
467493
no_of_tries: int,
494+
retry_info_map: Optional[Dict[str, int]] = None,
468495
) -&gt; Any:
469496
if no_of_tries == 0:
470497
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
@@ -481,6 +508,14 @@ <h2 class="section-title" id="header-classes">Classes</h2>
481508
Querier.__last_tried_index %= len(self.__hosts)
482509
url = current_host + path.get_as_string_dangerous()
483510

511+
max_retries = 5
512+
513+
if retry_info_map is None:
514+
retry_info_map = {}
515+
516+
if retry_info_map.get(url) is None:
517+
retry_info_map[url] = max_retries
518+
484519
ProcessState.get_instance().add_state(
485520
AllowedProcessStates.CALLING_SERVICE_IN_REQUEST_HELPER
486521
)
@@ -490,6 +525,20 @@ <h2 class="section-title" id="header-classes">Classes</h2>
490525
):
491526
Querier.__hosts_alive_for_testing.add(current_host)
492527

528+
if response.status_code == RATE_LIMIT_STATUS_CODE:
529+
retries_left = retry_info_map[url]
530+
531+
if retries_left &gt; 0:
532+
retry_info_map[url] = retries_left - 1
533+
534+
attempts_made = max_retries - retries_left
535+
delay = (10 + attempts_made * 250) / 1000
536+
537+
await asyncio.sleep(delay)
538+
return await self.__send_request_helper(
539+
path, method, http_function, no_of_tries, retry_info_map
540+
)
541+
493542
if is_4xx_error(response.status_code) or is_5xx_error(response.status_code): # type: ignore
494543
raise_general_exception(
495544
&#34;SuperTokens core threw an error for a &#34;
@@ -507,13 +556,20 @@ <h2 class="section-title" id="header-classes">Classes</h2>
507556
except JSONDecodeError:
508557
return response.text
509558

510-
except (ConnectionError, NetworkError, ConnectTimeout):
559+
except (ConnectionError, NetworkError, ConnectTimeout) as _:
511560
return await self.__send_request_helper(
512-
path, method, http_function, no_of_tries - 1
561+
path, method, http_function, no_of_tries - 1, retry_info_map
513562
)
514563
except Exception as e:
515564
raise_general_exception(e)</code></pre>
516565
</details>
566+
<h3>Class variables</h3>
567+
<dl>
568+
<dt id="supertokens_python.querier.Querier.api_version"><code class="name">var <span class="ident">api_version</span></code></dt>
569+
<dd>
570+
<div class="desc"></div>
571+
</dd>
572+
</dl>
517573
<h3>Static methods</h3>
518574
<dl>
519575
<dt id="supertokens_python.querier.Querier.get_hosts_alive_for_testing"><code class="name flex">
@@ -567,7 +623,7 @@ <h3>Static methods</h3>
567623
Querier.__init_called = True
568624
Querier.__hosts = hosts
569625
Querier.__api_key = api_key
570-
Querier.__api_version = None
626+
Querier.api_version = None
571627
Querier.__last_tried_index = 0
572628
Querier.__hosts_alive_for_testing = set()</code></pre>
573629
</details>
@@ -603,8 +659,8 @@ <h3>Methods</h3>
603659
<span>Expand source code</span>
604660
</summary>
605661
<pre><code class="python">async def get_api_version(self):
606-
if Querier.__api_version is not None:
607-
return Querier.__api_version
662+
if Querier.api_version is not None:
663+
return Querier.api_version
608664

609665
ProcessState.get_instance().add_state(
610666
AllowedProcessStates.CALLING_SERVICE_IN_GET_API_VERSION
@@ -630,8 +686,8 @@ <h3>Methods</h3>
630686
&#34;to find the right versions&#34;
631687
)
632688

633-
Querier.__api_version = api_version
634-
return Querier.__api_version</code></pre>
689+
Querier.api_version = api_version
690+
return Querier.api_version</code></pre>
635691
</details>
636692
</dd>
637693
<dt id="supertokens_python.querier.Querier.send_delete_request"><code class="name flex">
@@ -767,6 +823,7 @@ <h2>Index</h2>
767823
<li>
768824
<h4><code><a title="supertokens_python.querier.Querier" href="#supertokens_python.querier.Querier">Querier</a></code></h4>
769825
<ul class="">
826+
<li><code><a title="supertokens_python.querier.Querier.api_version" href="#supertokens_python.querier.Querier.api_version">api_version</a></code></li>
770827
<li><code><a title="supertokens_python.querier.Querier.get_api_version" href="#supertokens_python.querier.Querier.get_api_version">get_api_version</a></code></li>
771828
<li><code><a title="supertokens_python.querier.Querier.get_hosts_alive_for_testing" href="#supertokens_python.querier.Querier.get_hosts_alive_for_testing">get_hosts_alive_for_testing</a></code></li>
772829
<li><code><a title="supertokens_python.querier.Querier.get_instance" href="#supertokens_python.querier.Querier.get_instance">get_instance</a></code></li>

0 commit comments

Comments
 (0)