Release 0.3.5 (2023-06-01)

build_analytics:
  ALBS-1103 start using persistent HTTP connections
This commit is contained in:
Kirill Zhukov 2023-06-01 11:57:27 +02:00
parent d47fe3b4cd
commit 7c05bbacb6
3 changed files with 40 additions and 4 deletions

View File

@ -27,6 +27,8 @@ class APIclient():
self.api_root = api_root
self.jwt = jwt
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]:
ep = '/api/v1/builds'
@ -34,8 +36,7 @@ class APIclient():
params = {'pageNumber': page_num}
headers = {'accept': 'appilication/json'}
response = requests.get(
url, params=params, headers=headers, timeout=self.timeout)
response = self.__send_request(url, 'get', params, headers)
response.raise_for_status()
result = []
@ -54,7 +55,7 @@ class APIclient():
ep = f'/api/v1/builds/{build_id}'
url = urljoin(self.api_root, ep)
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:
return None
@ -228,3 +229,31 @@ class APIclient():
start_ts = stat.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()

View File

@ -99,7 +99,10 @@ def start(yml_path: str):
else:
logging.info('test tasks were updated')
# freeing up resources
extractor.db.close_conn()
extractor.api.close_session()
logging.info("Extraction was finished")
logging.info("Sleeping for %d seconds", config.scrape_interval)
time.sleep(config.scrape_interval)

View File

@ -33,4 +33,8 @@ build-analytics
0.3.4 (2023-05-12)
build_analytics
- Bigfix ALBS-1111
- Bigfix ALBS-1111
0.3.5 (2023-06-01)
build_analytics:
ALBS-1103 start using persistent HTTP connections