Skip to content

Commit 83655e1

Browse files
Add retries to download functions
To mitigate occasional connection errors #58
1 parent dd2e7ab commit 83655e1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

iatikit/utils/download.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import zipfile
99

1010
import requests
11+
from requests.exceptions import ConnectionError
12+
from retry import retry
1113

1214
from ..standard.codelist import CodelistSet
1315
from .config import CONFIG
1416
from . import helpers
1517

1618

19+
@retry(ConnectionError, tries=3, delay=1, backoff=2)
1720
def data():
1821
path = CONFIG['paths']['registry']
1922
# downloads from https://iati-data-dump.codeforiati.org
@@ -38,6 +41,7 @@ def data():
3841
_unlink(zip_filepath)
3942

4043

44+
@retry(ConnectionError, tries=3, delay=1, backoff=2)
4145
def metadata():
4246
logging.getLogger(__name__).info(
4347
'Downloading metadata from the IATI registry...')
@@ -127,6 +131,7 @@ def _get_codelist_mappings(versions):
127131
json.dump(organisation_mappings, handler)
128132

129133

134+
@retry(ConnectionError, tries=3, delay=1, backoff=2)
130135
def codelists():
131136
def get_list_of_codelists(version):
132137
if version in _VERY_OLD_IATI_VERSIONS:
@@ -218,6 +223,7 @@ def get_codelist(codelist_name, version):
218223
_get_codelist_mappings(all_versions)
219224

220225

226+
@retry(ConnectionError, tries=3, delay=1, backoff=2)
221227
def schemas():
222228
path = join(CONFIG['paths']['standard'], 'schemas')
223229
shutil.rmtree(path, ignore_errors=True)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
retry
12
-e .

0 commit comments

Comments
 (0)