55import types
66import requests
77import asyncio
8+ from urllib3 .util .retry import Retry
9+ from requests .adapters import HTTPAdapter
810from skyflow .vault ._insert import getInsertRequestBody , processResponse , convertResponse
911from skyflow .vault ._update import sendUpdateRequests , createUpdateResponseBody
1012from skyflow .vault ._config import Configuration , ConnectionConfig , DeleteOptions , DetokenizeOptions , GetOptions , InsertOptions , UpdateOptions , QueryOptions
@@ -36,6 +38,18 @@ def __init__(self, config: Configuration):
3638 raise SkyflowError (SkyflowErrorCodes .INVALID_INPUT , SkyflowErrorMessages .TOKEN_PROVIDER_ERROR .value % (
3739 str (type (config .tokenProvider ))), interface = interface )
3840
41+ retry_strategy = Retry (
42+ total = 3 ,
43+ connect = 5 ,
44+ backoff_factor = 0.5 ,
45+ status_forcelist = [500 , 502 , 503 , 504 ],
46+ raise_on_status = True ,
47+ )
48+
49+ self .session = requests .Session ()
50+ adapter = HTTPAdapter (pool_connections = 1 , pool_maxsize = 20 , pool_block = False , max_retries = retry_strategy )
51+ self .session .mount ("https://" , adapter )
52+
3953 self .vaultID = config .vaultID
4054 self .vaultURL = config .vaultURL .rstrip ('/' )
4155 self .tokenProvider = config .tokenProvider
@@ -45,7 +59,6 @@ def __init__(self, config: Configuration):
4559 def insert (self , records : dict , options : InsertOptions = InsertOptions ()):
4660 interface = InterfaceName .INSERT .value
4761 log_info (InfoMessages .INSERT_TRIGGERED .value , interface = interface )
48-
4962 self ._checkConfig (interface )
5063
5164 jsonBody = getInsertRequestBody (records , options )
@@ -54,11 +67,19 @@ def insert(self, records: dict, options: InsertOptions = InsertOptions()):
5467 self .storedToken , self .tokenProvider , interface )
5568 headers = {
5669 "Authorization" : "Bearer " + self .storedToken ,
57- "sky-metadata" : json .dumps (getMetrics ())
70+ "sky-metadata" : json .dumps (getMetrics ()),
71+ # "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
5872 }
59-
60- response = requests .post (requestURL , data = jsonBody , headers = headers )
73+ # response = requests.post(requestURL, data=jsonBody, headers=headers)
74+ response = self .session .post (
75+ requestURL ,
76+ data = jsonBody ,
77+ headers = headers ,
78+ # timeout=(5, 300),
79+ )
80+ print (">>> raw response: " , response .history )
6181 processedResponse = processResponse (response )
82+ print (">>> processedResponse local: " , processedResponse )
6283 result , partial = convertResponse (records , processedResponse , options )
6384 if partial :
6485 log_error (SkyflowErrorMessages .BATCH_INSERT_PARTIAL_SUCCESS .value , interface )
0 commit comments