Release 0.3.5 (2023-06-01)
build_analytics: ALBS-1103 start using persistent HTTP connections
This commit is contained in:
parent
d47fe3b4cd
commit
7c05bbacb6
@ -27,6 +27,8 @@ class APIclient():
|
|||||||
self.api_root = api_root
|
self.api_root = api_root
|
||||||
self.jwt = jwt
|
self.jwt = jwt
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
# will be set at first call of __send_request
|
||||||
|
self.session: Optional[requests.Session] = None
|
||||||
|
|
||||||
def get_builds(self, page_num: int = 1) -> List[Build]:
|
def get_builds(self, page_num: int = 1) -> List[Build]:
|
||||||
ep = '/api/v1/builds'
|
ep = '/api/v1/builds'
|
||||||
@ -34,8 +36,7 @@ class APIclient():
|
|||||||
params = {'pageNumber': page_num}
|
params = {'pageNumber': page_num}
|
||||||
headers = {'accept': 'appilication/json'}
|
headers = {'accept': 'appilication/json'}
|
||||||
|
|
||||||
response = requests.get(
|
response = self.__send_request(url, 'get', params, headers)
|
||||||
url, params=params, headers=headers, timeout=self.timeout)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
@ -54,7 +55,7 @@ class APIclient():
|
|||||||
ep = f'/api/v1/builds/{build_id}'
|
ep = f'/api/v1/builds/{build_id}'
|
||||||
url = urljoin(self.api_root, ep)
|
url = urljoin(self.api_root, ep)
|
||||||
headers = {'accept': 'application/json'}
|
headers = {'accept': 'application/json'}
|
||||||
response = requests.get(url, headers=headers, timeout=self.timeout)
|
response = self.__send_request(url, 'get', headers=headers)
|
||||||
|
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
return None
|
return None
|
||||||
@ -228,3 +229,31 @@ class APIclient():
|
|||||||
start_ts = stat.start_ts
|
start_ts = stat.start_ts
|
||||||
|
|
||||||
return start_ts
|
return start_ts
|
||||||
|
|
||||||
|
def __send_request(self,
|
||||||
|
url: str,
|
||||||
|
method: str,
|
||||||
|
params: Optional[Dict[str, Any]] = None,
|
||||||
|
headers: Optional[Dict[str, Any]] = None,
|
||||||
|
) -> requests.Response:
|
||||||
|
"""
|
||||||
|
Simple wrapper around requests.get/posts.. methods
|
||||||
|
so we can use same session between API calls
|
||||||
|
"""
|
||||||
|
if not self.session:
|
||||||
|
self.session = requests.Session()
|
||||||
|
|
||||||
|
m = getattr(self.session, method, None)
|
||||||
|
if not m:
|
||||||
|
raise ValueError(f"method {method} is not supported")
|
||||||
|
|
||||||
|
# pylint: disable=not-callable
|
||||||
|
return m(url, params=params, headers=headers, timeout=self.timeout)
|
||||||
|
|
||||||
|
def close_session(self):
|
||||||
|
if self.session:
|
||||||
|
self.session.close()
|
||||||
|
self.session = None
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.close_session()
|
||||||
|
@ -99,7 +99,10 @@ def start(yml_path: str):
|
|||||||
else:
|
else:
|
||||||
logging.info('test tasks were updated')
|
logging.info('test tasks were updated')
|
||||||
|
|
||||||
|
# freeing up resources
|
||||||
extractor.db.close_conn()
|
extractor.db.close_conn()
|
||||||
|
extractor.api.close_session()
|
||||||
|
|
||||||
logging.info("Extraction was finished")
|
logging.info("Extraction was finished")
|
||||||
logging.info("Sleeping for %d seconds", config.scrape_interval)
|
logging.info("Sleeping for %d seconds", config.scrape_interval)
|
||||||
time.sleep(config.scrape_interval)
|
time.sleep(config.scrape_interval)
|
||||||
|
@ -34,3 +34,7 @@ build-analytics
|
|||||||
0.3.4 (2023-05-12)
|
0.3.4 (2023-05-12)
|
||||||
build_analytics
|
build_analytics
|
||||||
- Bigfix ALBS-1111
|
- Bigfix ALBS-1111
|
||||||
|
|
||||||
|
0.3.5 (2023-06-01)
|
||||||
|
build_analytics:
|
||||||
|
ALBS-1103 start using persistent HTTP connections
|
Loading…
Reference in New Issue
Block a user