Refactor and deduplicate HTTP requests code in listers
Numerous listers were using the same page_request method or equivalent in their implementation so prefer to deduplicate that code by adding an http_request method in base lister class: swh.lister.pattern.Lister. That method simply wraps a call to requests.Session.request and logs some useful info for debugging and error reporting, also an HTTPError will be raised if a request ends up with an error. All listers using that new method now benefit of requests retry when an HTTP error occurs thanks to the use of the http_retry decorator.
This commit is contained in:
parent
9c55acd286
commit
db6ce12e9e
28 changed files with 174 additions and 449 deletions
|
@ -7,8 +7,6 @@ import datetime
|
|||
import logging
|
||||
from typing import Any, Dict, Iterator, List, Optional
|
||||
|
||||
import requests
|
||||
|
||||
from swh.scheduler.interface import SchedulerInterface
|
||||
from swh.scheduler.model import ListedOrigin
|
||||
|
||||
|
@ -65,7 +63,7 @@ class AurLister(StatelessLister[AurListerPage]):
|
|||
a directory Path where the archive has been downloaded to.
|
||||
"""
|
||||
url = self.DEFAULT_PACKAGES_INDEX_URL.format(base_url=self.url)
|
||||
return requests.get(url).json()
|
||||
return self.http_request(url).json()
|
||||
|
||||
def get_pages(self) -> Iterator[AurListerPage]:
|
||||
"""Yield an iterator which returns 'page'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue