Skip to content

Commit

Permalink
Merge pull request #126 from mganisin/backoff-404
Browse files Browse the repository at this point in the history
Limit backoff on wait_for_tenant just for 404 errors.
  • Loading branch information
Marian Ganisin authored Jul 21, 2022
2 parents b0dc196 + ab36a65 commit 0a422f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions threescale_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ def wait_for_tenant(self) -> bool:
# ultimate readiness check. There might be duplicates though, so
# worth to review it one day
try:
return self.account_plans.exists() \
return self.account_plans.exists(throws=True) \
and len(self.account_plans.fetch()["plans"]) >= 1 \
and len(self.account_plans.list()) >= 1 \
and self.accounts.exists() \
and self.accounts.exists(throws=True) \
and len(self.accounts.list()) >= 1 \
and self.services.exists() \
and self.services.exists(throws=True) \
and len(self.services.list()) >= 1
except errors.ApiClientError as err:
if err.code in (404, 503):
log.info("wait_for_tenant failed: %s", err)
return False
raise err
except Exception as err:
log.info("wait_for_tenant failed: %s", err)
return False
Expand Down
4 changes: 2 additions & 2 deletions threescale_api/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def delete(self, entity_id: int = None, **kwargs) -> bool:
response = self.rest.delete(url=url, **kwargs)
return response.ok

def exists(self, entity_id=None, **kwargs) -> bool:
def exists(self, entity_id=None, throws=False, **kwargs) -> bool:
"""Check whether the resource exists
Args:
entity_id(int): Entity id
Expand All @@ -101,7 +101,7 @@ def exists(self, entity_id=None, **kwargs) -> bool:
"""
log.info(self._log_message("[EXIST] Resource exist ", entity_id=entity_id, args=kwargs))
url = self._entity_url(entity_id=entity_id)
response = self.rest.get(url=url, throws=False, **kwargs)
response = self.rest.get(url=url, throws=throws, **kwargs)
return response.ok

def update(self, entity_id=None, params: dict = None, **kwargs) -> 'DefaultResource':
Expand Down

0 comments on commit 0a422f3

Please sign in to comment.