Skip to content

Commit

Permalink
Merge pull request #119 from mganisin/custom-waiting
Browse files Browse the repository at this point in the history
make waiting time in client init customizable
  • Loading branch information
Marian Ganisin authored Feb 3, 2022
2 parents 025ce77 + 9da777f commit e76cd55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions threescale_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@

class ThreeScaleClient:
def __init__(self, url: str, token: str,
throws: bool = True, ssl_verify: bool = True, wait: bool = False):
throws: bool = True, ssl_verify: bool = True, wait: int = -1):
"""Creates instance of the 3scale client
Args:
url: 3scale instance url
token: Access token
throws: Whether it should throw an error
ssl_verify: Whether to verify ssl
wait: Whether to do extra checks of 3scale availability
wait: Whether to wait for 3scale availability, negative number == no waiting
positive number == wait another extra seconds
"""
self._rest = RestApiClient(url=url, token=token, throws=throws, ssl_verify=ssl_verify)
self._services = resources.Services(self, instance_klass=resources.Service)
Expand Down Expand Up @@ -50,12 +51,12 @@ def __init__(self, url: str, token: str,
self._fields_definitions =\
resources.FieldsDefinitions(self, instance_klass=resources.FieldsDefinition)

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

@backoff.on_predicate(backoff.fibo, lambda ready: not ready, max_tries=8, jitter=None)
def wait_for_tenant(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def wait_tenant_ready(self) -> bool:
"""
return self.admin_api().wait_for_tenant()

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

0 comments on commit e76cd55

Please sign in to comment.