Commit 4b5709a846c8230bc284951c49ae6f1d1c3789ec

Authored by kosaniak
Committed by GitHub
2 parents bb751bae 98c3e426

Merge pull request #538 from ITVaan/fix_retry_after

Add sleep for 429
... ... @@ -2,8 +2,9 @@ from openprocurement_client.client import Client, EDRClient
2 2 from openprocurement_client.document_service_client \
3 3 import DocumentServiceClient
4 4 from openprocurement_client.exceptions import IdNotFound
5   -from restkit.errors import RequestFailed, BadStatusLine
  5 +from restkit.errors import RequestFailed, BadStatusLine, ResourceError
6 6 from retrying import retry
  7 +from time import sleep
7 8 import os
8 9 import urllib
9 10
... ... @@ -46,7 +47,14 @@ class StableEDRClient(EDRClient):
46 47 @retry(stop_max_attempt_number=100, wait_random_min=500,
47 48 wait_random_max=4000, retry_on_exception=retry_if_request_failed)
48 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 60 def prepare_edr_wrapper(host_url, api_version, username, password):
... ...
Please register or login to post a comment