Commit 4b5709a846c8230bc284951c49ae6f1d1c3789ec
Committed by
GitHub
Merge pull request #538 from ITVaan/fix_retry_after
Add sleep for 429
Showing
1 changed file
with
10 additions
and
2 deletions
@@ -2,8 +2,9 @@ from openprocurement_client.client import Client, EDRClient | @@ -2,8 +2,9 @@ from openprocurement_client.client import Client, EDRClient | ||
2 | from openprocurement_client.document_service_client \ | 2 | from openprocurement_client.document_service_client \ |
3 | import DocumentServiceClient | 3 | import DocumentServiceClient |
4 | from openprocurement_client.exceptions import IdNotFound | 4 | from openprocurement_client.exceptions import IdNotFound |
5 | -from restkit.errors import RequestFailed, BadStatusLine | 5 | +from restkit.errors import RequestFailed, BadStatusLine, ResourceError |
6 | from retrying import retry | 6 | from retrying import retry |
7 | +from time import sleep | ||
7 | import os | 8 | import os |
8 | import urllib | 9 | import urllib |
9 | 10 | ||
@@ -46,7 +47,14 @@ class StableEDRClient(EDRClient): | @@ -46,7 +47,14 @@ class StableEDRClient(EDRClient): | ||
46 | @retry(stop_max_attempt_number=100, wait_random_min=500, | 47 | @retry(stop_max_attempt_number=100, wait_random_min=500, |
47 | wait_random_max=4000, retry_on_exception=retry_if_request_failed) | 48 | wait_random_max=4000, retry_on_exception=retry_if_request_failed) |
48 | def request(self, *args, **kwargs): | 49 | def request(self, *args, **kwargs): |
49 | - return super(StableEDRClient, self).request(*args, **kwargs) | 50 | + try: |
51 | + res = super(StableEDRClient, self).request(*args, **kwargs) | ||
52 | + except ResourceError as re: | ||
53 | + if re.status_int == 429: | ||
54 | + sleep(int(re.response.headers.get('Retry-After', '30'))) | ||
55 | + raise re | ||
56 | + else: | ||
57 | + return res | ||
50 | 58 | ||
51 | 59 | ||
52 | def prepare_edr_wrapper(host_url, api_version, username, password): | 60 | def prepare_edr_wrapper(host_url, api_version, username, password): |
Please
register
or
login
to post a comment