|
14 | 14 | # You should have received a copy of the GNU General Public |
15 | 15 | # License along with OctoBot. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | import asyncio |
17 | | -import base64 |
18 | 17 | import datetime |
19 | 18 | import time |
20 | 19 | import typing |
21 | 20 | import logging |
22 | | -import httpx |
23 | 21 | import uuid |
24 | 22 | import json |
25 | 23 | import contextlib |
@@ -66,41 +64,6 @@ def error_describer(): |
66 | 64 | raise errors.SessionTokenExpiredError(err) from err |
67 | 65 | raise |
68 | 66 |
|
69 | | - |
70 | | -def _httpx_retrier(f): |
71 | | - async def httpx_retrier_wrapper(*args, **kwargs): |
72 | | - resp = None |
73 | | - for i in range(0, HTTP_RETRY_COUNT): |
74 | | - error = None |
75 | | - try: |
76 | | - resp: httpx.Response = await f(*args, **kwargs) |
77 | | - if resp.status_code in (502, 503, 520): |
78 | | - # waking up or SLA issue, retry |
79 | | - error = f"{resp.status_code} error {resp.reason_phrase}" |
80 | | - commons_logging.get_logger(__name__).debug( |
81 | | - f"{f.__name__}(args={args[1:]}) failed with {error} after {i+1} attempts, retrying." |
82 | | - ) |
83 | | - else: |
84 | | - if i > 0: |
85 | | - commons_logging.get_logger(__name__).debug( |
86 | | - f"{f.__name__}(args={args[1:]}) succeeded after {i+1} attempts" |
87 | | - ) |
88 | | - return resp |
89 | | - except httpx.ReadTimeout as err: |
90 | | - error = f"{err} ({err.__class__.__name__})" |
91 | | - # retry |
92 | | - commons_logging.get_logger(__name__).debug( |
93 | | - f"Error on {f.__name__}(args={args[1:]}) " |
94 | | - f"request, retrying now. Attempt {i+1} / {HTTP_RETRY_COUNT} ({error})." |
95 | | - ) |
96 | | - # no more attempts |
97 | | - if resp: |
98 | | - resp.raise_for_status() |
99 | | - return resp |
100 | | - else: |
101 | | - raise errors.RequestError(f"Failed to execute {f.__name__}(args={args[1:]} kwargs={kwargs})") |
102 | | - return httpx_retrier_wrapper |
103 | | - |
104 | 67 | class CommunitySupabaseClient(supabase_client.AuthenticatedAsyncSupabaseClient): |
105 | 68 | """ |
106 | 69 | Octobot Community layer added to supabase_client.AuthenticatedSupabaseClient |
@@ -829,28 +792,6 @@ def _get_auth_key(self): |
829 | 792 | return session.access_token |
830 | 793 | return self.supabase_key |
831 | 794 |
|
832 | | - @_httpx_retrier |
833 | | - async def http_get(self, url: str, *args, params=None, headers=None, **kwargs) -> httpx.Response: |
834 | | - """ |
835 | | - Perform http get using the current supabase auth token |
836 | | - """ |
837 | | - params = params or {} |
838 | | - params["access_token"] = params.get("access_token", base64.b64encode(self._get_auth_key().encode()).decode()) |
839 | | - return await self.postgrest.session.get(url, *args, params=params, headers=headers, **kwargs) |
840 | | - |
841 | | - @_httpx_retrier |
842 | | - async def http_post( |
843 | | - self, url: str, *args, json=None, params=None, headers=None, **kwargs |
844 | | - ) -> httpx.Response: |
845 | | - """ |
846 | | - Perform http get using the current supabase auth token |
847 | | - """ |
848 | | - json_body = json or {} |
849 | | - json_body["access_token"] = json_body.get("access_token", self._get_auth_key()) |
850 | | - return await self.postgrest.session.post( |
851 | | - url, *args, json=json_body, params=params, headers=headers, **kwargs |
852 | | - ) |
853 | | - |
854 | 795 | @staticmethod |
855 | 796 | def get_formatted_time(timestamp: float) -> str: |
856 | 797 | return datetime.datetime.utcfromtimestamp(timestamp).isoformat('T') |
|
0 commit comments