Showing
1 changed file
with
14 additions
and
2 deletions
1 | from openprocurement_client.client import Client | 1 | from openprocurement_client.client import Client |
2 | from openprocurement_client.utils import get_tender_id_by_uaid | 2 | from openprocurement_client.utils import get_tender_id_by_uaid |
3 | from openprocurement_client.exceptions import IdNotFound | 3 | from openprocurement_client.exceptions import IdNotFound |
4 | +from restkit.errors import RequestFailed | ||
5 | +from retrying import retry | ||
6 | + | ||
7 | + | ||
8 | +def retry_if_request_failed(exception): | ||
9 | + return isinstance(exception, RequestFailed) | ||
10 | + | ||
11 | + | ||
12 | +class StableClient(Client): | ||
13 | + @retry(stop_max_attempt_number=100, wait_random_min=500, wait_random_max=4000, retry_on_exception=retry_if_request_failed) | ||
14 | + def request(self, *args, **kwargs): | ||
15 | + return super(StableClient, self).request(*args, **kwargs) | ||
4 | 16 | ||
5 | 17 | ||
6 | def prepare_api_wrapper(key, host_url, api_version): | 18 | def prepare_api_wrapper(key, host_url, api_version): |
7 | - return Client(key, host_url, api_version) | 19 | + return StableClient(key, host_url, api_version) |
20 | + | ||
8 | 21 | ||
9 | def get_complaint_internal_id(tender, complaintID): | 22 | def get_complaint_internal_id(tender, complaintID): |
10 | try: | 23 | try: |
@@ -21,4 +34,3 @@ def get_complaint_internal_id(tender, complaintID): | @@ -21,4 +34,3 @@ def get_complaint_internal_id(tender, complaintID): | ||
21 | except AttributeError: | 34 | except AttributeError: |
22 | pass | 35 | pass |
23 | raise IdNotFound | 36 | raise IdNotFound |
24 | - |
Please
register
or
login
to post a comment