Skip to content

Commit cb1e123

Browse files
committed
Fix
1 parent e677c72 commit cb1e123

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

transifex/native/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def init(
88
fetch_all_langs=False,
99
filter_tags=None,
1010
filter_status=None,
11+
fetch_timeout=0,
1112
):
1213
"""Initialize the framework.
1314
@@ -25,6 +26,8 @@ def init(
2526
:param bool fetch_all_langs: force pull all remote languages
2627
:param str filter_tags: fetch only content with tags
2728
:param str filter_status: fetch only content with specific translation status
29+
:param int fetch_timeout: maximum time in seconds to wait when fetching
30+
translations or locales from CDS
2831
"""
2932
if not tx.initialized:
3033
tx.init(
@@ -38,6 +41,7 @@ def init(
3841
fetch_all_langs=fetch_all_langs,
3942
filter_tags=filter_tags,
4043
filter_status=filter_status,
44+
fetch_timeout=fetch_timeout,
4145
)
4246

4347

transifex/native/cds.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
import time
44
from urllib.parse import urlencode
5-
from transifex.native.django import settings as native_settings
65

76
import requests
87
from transifex.native.consts import (KEY_CHARACTER_LIMIT,
@@ -58,7 +57,7 @@ class CDSHandler(object):
5857

5958
def __init__(self, configured_languages, token, secret=None,
6059
host=TRANSIFEX_CDS_HOST, fetch_all_langs=False,
61-
filter_tags=None, filter_status=None):
60+
filter_tags=None, filter_status=None, fetch_timeout=0):
6261
"""Constructor.
6362
6463
:param list configured_languages: a list of language codes for the
@@ -74,6 +73,7 @@ def __init__(self, configured_languages, token, secret=None,
7473
self.secret = secret
7574
self.host = host or TRANSIFEX_CDS_HOST
7675
self.etags = EtagStore()
76+
self.fetch_timeout = fetch_timeout
7777

7878
def fetch_languages(self):
7979
"""Fetch the languages defined in the CDS for the specific project.
@@ -368,7 +368,7 @@ def retry_get_request(self, *args, **kwargs):
368368
retries_5xx = 0
369369
last_response_status = 202
370370
start_ts = time.time()
371-
max_total_seconds = native_settings.TRANSIFEX_FETCH_TEMEOUT
371+
max_total_seconds = self.fetch_timeout
372372

373373
while True:
374374
response = requests.get(*args, **kwargs)

transifex/native/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def init(
4242
missing_policy=None, error_policy=None, cache=None,
4343
fetch_all_langs=False, filter_tags=None,
4444
filter_status=None,
45+
fetch_timeout=0,
4546
):
4647
"""Create an instance of the core framework class.
4748
@@ -62,6 +63,8 @@ def init(
6263
:param bool fetch_all_langs: force pull all remote languages
6364
:param str filter_tags: fetch only content with tags
6465
:param str filter_status: fetch only content with specific translation status
66+
:param int fetch_timeout: maximum time in seconds to wait when fetching
67+
translations or locales from CDS
6568
"""
6669
self._languages = languages
6770
self._cache = cache or MemoryCache()
@@ -72,6 +75,7 @@ def init(
7275
fetch_all_langs=fetch_all_langs,
7376
filter_tags=filter_tags,
7477
filter_status=filter_status,
78+
fetch_timeout=fetch_timeout,
7579
)
7680
self.initialized = True
7781

transifex/native/django/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def ready(self):
9494
fetch_all_langs=native_settings.TRANSIFEX_FETCH_ALL_LANGUAGES,
9595
filter_tags=native_settings.TRANSIFEX_FILTER_TAGS,
9696
filter_status=native_settings.TRANSIFEX_FILTER_STATUS,
97+
fetch_timeout=native_settings.TRANSIFEX_FETCH_TIMEOUT,
9798
)
9899

99100
if fetch_translations:

0 commit comments

Comments
 (0)