forked from platypush/platypush
Retry logic for Mercury API
This commit is contained in:
parent
d2bd49b364
commit
09d7d98ae3
1 changed files with 23 additions and 6 deletions
|
@ -65,13 +65,30 @@ class RssUpdates(HttpRequest):
|
||||||
|
|
||||||
def _parse_entry_content(self, link):
|
def _parse_entry_content(self, link):
|
||||||
response = None
|
response = None
|
||||||
|
err = None
|
||||||
|
n_tries = 5
|
||||||
|
|
||||||
|
for _ in range(0, n_tries):
|
||||||
try:
|
try:
|
||||||
self.logger.info('Parsing content for {}'.format(link))
|
self.logger.info('Parsing content for {}'.format(link))
|
||||||
response = requests.get('https://mercury.postlight.com/parser',
|
response = requests.get('https://mercury.postlight.com/parser',
|
||||||
params = {'url': link},
|
params = {'url': link},
|
||||||
headers = {'x-api-key': self.mercury_api_key })
|
headers = {'x-api-key': self.mercury_api_key })
|
||||||
except Exception as e: self.logger.exception(e)
|
except Exception as e:
|
||||||
|
err = e
|
||||||
|
|
||||||
|
if response.text:
|
||||||
|
err = None
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
if not response.text:
|
||||||
|
raise RuntimeError("No response from Mercury API for URL {} after {} tries"
|
||||||
|
.format(link, n_tries))
|
||||||
|
|
||||||
return response.json()['content'] if response and response.ok else None
|
return response.json()['content'] if response and response.ok else None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue