define Retriable Client & edit name class EmsEngine_TseIfb_AsyncClient
This commit is contained in:
1 parent
569a36edaa
commit
aa4d4bbabb
8 files changed
+168
-30
No files matched your search
@@ -2,6 +2,7 @@
|
||||
# Imports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
from .__utils import RetriableAsyncClient
|
||||
from httpx import (
|
||||
AsyncClient ,
|
||||
Timeout ,
|
||||
@@ -126,20 +127,23 @@ class AuthAsyncClient:
|
||||
headers = {'origin' : 'https://core.hedgetech.ir'}
|
||||
headers.update(token)
|
||||
|
||||
httpx_Client = AsyncClient(
|
||||
verify=True ,
|
||||
http1=False ,
|
||||
http2=True ,
|
||||
headers=headers,
|
||||
cookies=httpx_Client.cookies,
|
||||
timeout=Timeout(
|
||||
connect=.5,
|
||||
read=1,
|
||||
write=1,
|
||||
pool=.5,
|
||||
httpx_Client = RetriableAsyncClient(
|
||||
client = AsyncClient(
|
||||
verify=True ,
|
||||
http1=False ,
|
||||
http2=True ,
|
||||
headers=headers,
|
||||
cookies=httpx_Client.cookies,
|
||||
timeout=Timeout(
|
||||
connect=.250,
|
||||
read=1.5,
|
||||
write=1.5,
|
||||
pool=.250,
|
||||
),
|
||||
),
|
||||
retries= 10
|
||||
)
|
||||
|
||||
|
||||
return cls(
|
||||
httpx_Client = httpx_Client,
|
||||
token = token
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# Imports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
from .__utils import RetriableSyncClient
|
||||
from httpx import (
|
||||
Client ,
|
||||
Timeout ,
|
||||
@@ -128,24 +129,27 @@ class AuthSyncClient:
|
||||
token = login_res.json()
|
||||
headers = {'origin' : 'https://core.hedgetech.ir'}
|
||||
headers.update(token)
|
||||
|
||||
httpx_Client = Client(
|
||||
verify=True ,
|
||||
http1=False ,
|
||||
http2=True ,
|
||||
headers=headers,
|
||||
cookies=httpx_Client.cookies,
|
||||
timeout=Timeout(
|
||||
connect=.5,
|
||||
read=1,
|
||||
write=1,
|
||||
pool=.5,
|
||||
),
|
||||
)
|
||||
|
||||
httpx_Client = RetriableSyncClient(
|
||||
client = Client(
|
||||
verify=True ,
|
||||
http1=False ,
|
||||
http2=True ,
|
||||
headers=headers,
|
||||
cookies=httpx_Client.cookies,
|
||||
timeout=Timeout(
|
||||
connect=.250,
|
||||
read=1.5,
|
||||
write=1.5,
|
||||
pool=.250,
|
||||
),
|
||||
),
|
||||
retries= 10
|
||||
)
|
||||
|
||||
return cls(
|
||||
httpx_Client = httpx_Client,
|
||||
token = login_res.json()
|
||||
token = token
|
||||
)
|
||||
|
||||
else :
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# ========================================|======================================== #
|
||||
# Exports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
__all__ = [
|
||||
'RetriableAsyncClient'
|
||||
]
|
||||
|
||||
# ========================================|======================================== #
|
||||
# Imports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
from httpx import (
|
||||
AsyncClient,
|
||||
|
||||
ConnectTimeout,
|
||||
PoolTimeout,
|
||||
ReadTimeout,
|
||||
WriteTimeout,
|
||||
)
|
||||
|
||||
# ========================================|======================================== #
|
||||
# Class Definitions #
|
||||
# ========================================|======================================== #
|
||||
|
||||
|
||||
class RetriableAsyncClient:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
client: AsyncClient,
|
||||
retries: int = 10,
|
||||
)-> AsyncClient:
|
||||
|
||||
self._client = client
|
||||
self._retries = retries
|
||||
|
||||
async def _request(self, method: str, **kwargs):
|
||||
attempt = self._retries
|
||||
|
||||
while True:
|
||||
try:
|
||||
return await getattr(self._client, method)(**kwargs)
|
||||
|
||||
except (
|
||||
ConnectTimeout,
|
||||
PoolTimeout,
|
||||
ReadTimeout,
|
||||
WriteTimeout,
|
||||
):
|
||||
if attempt <= 0:
|
||||
raise
|
||||
attempt -= 1
|
||||
|
||||
def __getattr__(self, name: str):
|
||||
attr = getattr(self._client, name)
|
||||
|
||||
if name in {"get", "post", "put", "delete", "patch", "options", "head"}:
|
||||
async def wrapper(**kwargs):
|
||||
return await self._request(name, **kwargs)
|
||||
return wrapper
|
||||
|
||||
return attr
|
||||
@@ -0,0 +1,65 @@
|
||||
# ========================================|======================================== #
|
||||
# Exports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
__all__ = [
|
||||
'RetriableSyncClient'
|
||||
]
|
||||
|
||||
# ========================================|======================================== #
|
||||
# Imports #
|
||||
# ========================================|======================================== #
|
||||
|
||||
from httpx import (
|
||||
Client,
|
||||
|
||||
ConnectTimeout,
|
||||
PoolTimeout,
|
||||
ReadTimeout,
|
||||
WriteTimeout,
|
||||
)
|
||||
|
||||
# ========================================|======================================== #
|
||||
# Class Definitions #
|
||||
# ========================================|======================================== #
|
||||
|
||||
|
||||
class RetriableSyncClient:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
client: Client,
|
||||
retries: int = 10,
|
||||
)-> Client:
|
||||
|
||||
self._client = client
|
||||
self._retries = retries
|
||||
|
||||
def _request(self, method: str, **kwargs):
|
||||
attempt = self._retries
|
||||
|
||||
while True:
|
||||
try:
|
||||
return getattr(self._client, method)(**kwargs)
|
||||
|
||||
except (
|
||||
ConnectTimeout,
|
||||
PoolTimeout,
|
||||
ReadTimeout,
|
||||
WriteTimeout,
|
||||
):
|
||||
if attempt <= 0:
|
||||
raise
|
||||
attempt -= 1
|
||||
|
||||
def __getattr__(self, name: str):
|
||||
|
||||
attr = getattr(self._client, name)
|
||||
|
||||
if name in {"get", "post", "put", "delete", "patch", "options", "head"}:
|
||||
|
||||
def wrapper(**kwargs):
|
||||
return self._request(name, **kwargs)
|
||||
return wrapper
|
||||
|
||||
return attr
|
||||
@@ -0,0 +1,2 @@
|
||||
from .__RetriableAsyncClient import *
|
||||
from .__RetriableSyncClient import *
|
||||
@@ -1,4 +1,4 @@
|
||||
from .__tse_ifb import (
|
||||
EmsEngine_TseIfb_SyncClient,
|
||||
EmsEngine_TseIfb_ASyncClient
|
||||
EmsEngine_TseIfb_AsyncClient
|
||||
)
|
||||
@@ -148,7 +148,7 @@ class Order:
|
||||
|
||||
# ================================================================================= #
|
||||
|
||||
class EmsEngine_TseIfb_ASyncClient:
|
||||
class EmsEngine_TseIfb_AsyncClient:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from .__SyncClient import EmsEngine_TseIfb_SyncClient
|
||||
from .__AsyncClient import EmsEngine_TseIfb_ASyncClient
|
||||
from .__AsyncClient import EmsEngine_TseIfb_AsyncClient
|
||||
Reference in new issue
Block a user