Skip to content

Commit 9da777f

Browse files
author
Marian Ganisin
committed
make waiting time in client init customizable
1 parent 025ce77 commit 9da777f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

threescale_api/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212

1313
class ThreeScaleClient:
1414
def __init__(self, url: str, token: str,
15-
throws: bool = True, ssl_verify: bool = True, wait: bool = False):
15+
throws: bool = True, ssl_verify: bool = True, wait: int = -1):
1616
"""Creates instance of the 3scale client
1717
Args:
1818
url: 3scale instance url
1919
token: Access token
2020
throws: Whether it should throw an error
2121
ssl_verify: Whether to verify ssl
22-
wait: Whether to do extra checks of 3scale availability
22+
wait: Whether to wait for 3scale availability, negative number == no waiting
23+
positive number == wait another extra seconds
2324
"""
2425
self._rest = RestApiClient(url=url, token=token, throws=throws, ssl_verify=ssl_verify)
2526
self._services = resources.Services(self, instance_klass=resources.Service)
@@ -50,12 +51,12 @@ def __init__(self, url: str, token: str,
5051
self._fields_definitions =\
5152
resources.FieldsDefinitions(self, instance_klass=resources.FieldsDefinition)
5253

53-
if wait:
54+
if wait >= 0:
5455
self.wait_for_tenant()
5556
# TODO: all the implemented checks aren't enough yet
5657
# 3scale can still return 404/409 error, therefore slight artificial sleep
5758
# here to mitigate the problem. This requires proper fix in checks
58-
time.sleep(16)
59+
time.sleep(wait)
5960

6061
@backoff.on_predicate(backoff.fibo, lambda ready: not ready, max_tries=8, jitter=None)
6162
def wait_for_tenant(self) -> bool:

threescale_api/resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ def wait_tenant_ready(self) -> bool:
11191119
"""
11201120
return self.admin_api().wait_for_tenant()
11211121

1122-
def admin_api(self, ssl_verify=True, wait=False) -> 'client.ThreeScaleClient':
1122+
def admin_api(self, ssl_verify=True, wait=-1) -> 'client.ThreeScaleClient':
11231123
"""
11241124
Returns admin api client for tenant.
11251125
Its strongly recommended to call this with wait=True

0 commit comments

Comments
 (0)