Skip to content

Commit

Permalink
adding dev-v0.15.3 tag to this commit to ensure building
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Aug 28, 2023
1 parent 8bb55c6 commit a64a384
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
5 changes: 3 additions & 2 deletions html/supertokens_python/constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
from __future__ import annotations

SUPPORTED_CDI_VERSIONS = [&#34;3.0&#34;]
VERSION = &#34;0.15.2&#34;
VERSION = &#34;0.15.3&#34;
TELEMETRY = &#34;/telemetry&#34;
USER_COUNT = &#34;/users/count&#34;
USER_DELETE = &#34;/user/remove&#34;
Expand All @@ -56,7 +56,8 @@ <h1 class="title">Module <code>supertokens_python.constants</code></h1>
API_VERSION = &#34;/apiversion&#34;
API_VERSION_HEADER = &#34;cdi-version&#34;
DASHBOARD_VERSION = &#34;0.7&#34;
HUNDRED_YEARS_IN_MS = 3153600000000</code></pre>
HUNDRED_YEARS_IN_MS = 3153600000000
RATE_LIMIT_STATUS_CODE = 429</code></pre>
</details>
</section>
<section>
Expand Down
12 changes: 9 additions & 3 deletions html/supertokens_python/normalised_url_path.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ <h1 class="title">Module <code>supertokens_python.normalised_url_path</code></h1

def is_a_recipe_path(self) -&gt; bool:
parts = self.__value.split(&#34;/&#34;)
return parts[1] == &#34;recipe&#34; or parts[2] == &#34;recipe&#34;
return (len(parts) &gt; 1 and parts[1] == &#34;recipe&#34;) or (
len(parts) &gt; 2 and parts[2] == &#34;recipe&#34;
)


def normalise_url_path_or_throw_error(input_str: str) -&gt; str:
Expand Down Expand Up @@ -247,7 +249,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>

def is_a_recipe_path(self) -&gt; bool:
parts = self.__value.split(&#34;/&#34;)
return parts[1] == &#34;recipe&#34; or parts[2] == &#34;recipe&#34;</code></pre>
return (len(parts) &gt; 1 and parts[1] == &#34;recipe&#34;) or (
len(parts) &gt; 2 and parts[2] == &#34;recipe&#34;
)</code></pre>
</details>
<h3>Methods</h3>
<dl>
Expand Down Expand Up @@ -301,7 +305,9 @@ <h3>Methods</h3>
</summary>
<pre><code class="python">def is_a_recipe_path(self) -&gt; bool:
parts = self.__value.split(&#34;/&#34;)
return parts[1] == &#34;recipe&#34; or parts[2] == &#34;recipe&#34;</code></pre>
return (len(parts) &gt; 1 and parts[1] == &#34;recipe&#34;) or (
len(parts) &gt; 2 and parts[2] == &#34;recipe&#34;
)</code></pre>
</details>
</dd>
<dt id="supertokens_python.normalised_url_path.NormalisedURLPath.startswith"><code class="name flex">
Expand Down
59 changes: 54 additions & 5 deletions html/supertokens_python/querier.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
# under the License.
from __future__ import annotations

import asyncio

from json import JSONDecodeError
from os import environ
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Optional

from httpx import AsyncClient, ConnectTimeout, NetworkError, Response

Expand All @@ -53,6 +55,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
API_VERSION_HEADER,
RID_KEY_HEADER,
SUPPORTED_CDI_VERSIONS,
RATE_LIMIT_STATUS_CODE,
)
from .normalised_url_path import NormalisedURLPath

Expand Down Expand Up @@ -250,6 +253,7 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
method: str,
http_function: Callable[[str], Awaitable[Response]],
no_of_tries: int,
retry_info_map: Optional[Dict[str, int]] = None,
) -&gt; Any:
if no_of_tries == 0:
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
Expand All @@ -266,6 +270,14 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
Querier.__last_tried_index %= len(self.__hosts)
url = current_host + path.get_as_string_dangerous()

max_retries = 5

if retry_info_map is None:
retry_info_map = {}

if retry_info_map.get(url) is None:
retry_info_map[url] = max_retries

ProcessState.get_instance().add_state(
AllowedProcessStates.CALLING_SERVICE_IN_REQUEST_HELPER
)
Expand All @@ -275,6 +287,20 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
):
Querier.__hosts_alive_for_testing.add(current_host)

if response.status_code == RATE_LIMIT_STATUS_CODE:
retries_left = retry_info_map[url]

if retries_left &gt; 0:
retry_info_map[url] = retries_left - 1

attempts_made = max_retries - retries_left
delay = (10 + attempts_made * 250) / 1000

await asyncio.sleep(delay)
return await self.__send_request_helper(
path, method, http_function, no_of_tries, retry_info_map
)

if is_4xx_error(response.status_code) or is_5xx_error(response.status_code): # type: ignore
raise_general_exception(
&#34;SuperTokens core threw an error for a &#34;
Expand All @@ -292,9 +318,9 @@ <h1 class="title">Module <code>supertokens_python.querier</code></h1>
except JSONDecodeError:
return response.text

except (ConnectionError, NetworkError, ConnectTimeout):
except (ConnectionError, NetworkError, ConnectTimeout) as _:
return await self.__send_request_helper(
path, method, http_function, no_of_tries - 1
path, method, http_function, no_of_tries - 1, retry_info_map
)
except Exception as e:
raise_general_exception(e)</code></pre>
Expand Down Expand Up @@ -503,6 +529,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
method: str,
http_function: Callable[[str], Awaitable[Response]],
no_of_tries: int,
retry_info_map: Optional[Dict[str, int]] = None,
) -&gt; Any:
if no_of_tries == 0:
raise_general_exception(&#34;No SuperTokens core available to query&#34;)
Expand All @@ -519,6 +546,14 @@ <h2 class="section-title" id="header-classes">Classes</h2>
Querier.__last_tried_index %= len(self.__hosts)
url = current_host + path.get_as_string_dangerous()

max_retries = 5

if retry_info_map is None:
retry_info_map = {}

if retry_info_map.get(url) is None:
retry_info_map[url] = max_retries

ProcessState.get_instance().add_state(
AllowedProcessStates.CALLING_SERVICE_IN_REQUEST_HELPER
)
Expand All @@ -528,6 +563,20 @@ <h2 class="section-title" id="header-classes">Classes</h2>
):
Querier.__hosts_alive_for_testing.add(current_host)

if response.status_code == RATE_LIMIT_STATUS_CODE:
retries_left = retry_info_map[url]

if retries_left &gt; 0:
retry_info_map[url] = retries_left - 1

attempts_made = max_retries - retries_left
delay = (10 + attempts_made * 250) / 1000

await asyncio.sleep(delay)
return await self.__send_request_helper(
path, method, http_function, no_of_tries, retry_info_map
)

if is_4xx_error(response.status_code) or is_5xx_error(response.status_code): # type: ignore
raise_general_exception(
&#34;SuperTokens core threw an error for a &#34;
Expand All @@ -545,9 +594,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
except JSONDecodeError:
return response.text

except (ConnectionError, NetworkError, ConnectTimeout):
except (ConnectionError, NetworkError, ConnectTimeout) as _:
return await self.__send_request_helper(
path, method, http_function, no_of_tries - 1
path, method, http_function, no_of_tries - 1, retry_info_map
)
except Exception as e:
raise_general_exception(e)</code></pre>
Expand Down

0 comments on commit a64a384

Please sign in to comment.