Skip to content

Commit

Permalink
Merge pull request #1185 from resource-watch/foo_053
Browse files Browse the repository at this point in the history
add retries for requests
  • Loading branch information
weiqi-tori authored Dec 12, 2023
2 parents 328f660 + 8e5d63e commit 5eb4f34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions foo_053_alerts_price_spikes/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.7
FROM python:3.9
MAINTAINER Weiqi Zhou <weiqi.zhou@wri.org>
#Note this script was originally developed by Nathan Suberi <nathan.suberi@wri.org> and Amelia Snyder <amelia.snyder@wri.org>

# install core libraries
RUN apt-get update
# install application libraries
RUN pip install --upgrade pip
RUN pip install requests==2.22.0
RUN pip install requests
RUN pip install -e git+https://github.com/resource-watch/cartosql.py.git#egg=cartosql
RUN pip install shapely
RUN pip install numpy==1.18.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _refresh_token(self, scopes):
raise TokenScopeError(f'Could not acquire requested scopes: {scopes}')
self.tokens_by_scopes[scopes] = resp_data['access_token']

@backoff.on_exception(backoff.expo, (ApiServerError, ApiNotAuthorizedError), max_tries=5)
@backoff.on_exception(backoff.expo, (ApiServerError, ApiNotAuthorizedError), max_tries=8, base=10)
def _invoke(self, endpoint_name, params=None, body=None):
if endpoint_name not in API_ENDPOINTS:
raise ValueError('Invalid endpoint invoked. Check the system configuration')
Expand All @@ -88,13 +88,13 @@ def _invoke(self, endpoint_name, params=None, body=None):
print('unauthorized. Retrying...')
raise ApiNotAuthorizedError()
if resp.status_code >= httpx.codes.INTERNAL_SERVER_ERROR:
print('Internal server error. Retrying...')
print('Internal server issue. Retrying...')
raise ApiServerError()
if resp.status_code == httpx.codes.NOT_FOUND:
raise NotFoundError()
if httpx.codes.BAD_REQUEST <= resp.status_code < httpx.codes.INTERNAL_SERVER_ERROR:
print('Http client error! Not retrying (as it would be useless)')
raise HTTPError(f'HTTP Client error ({resp.status_code})')
print('Http client issue! Not retrying (as it would be useless)')
raise HTTPError(f'HTTP Client issue ({resp.status_code})')

return resp.json()

Expand Down

0 comments on commit 5eb4f34

Please sign in to comment.