Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait for status update #186

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sdk/turing/router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self,
environment_name: str,
monitoring_url: str,
status: str,
version: int = None,
config: Dict = None,
endpoint: str = None,
**kwargs):
Expand All @@ -47,8 +48,10 @@ def __init__(self,

if config is not None:
self._config = RouterConfig(name=name, environment_name=environment_name, **config)
self._version = config.get('version')
deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
else:
self._config = None
self._config = config
self._version = version

@property
def id(self) -> int:
Expand Down Expand Up @@ -82,6 +85,10 @@ def status(self) -> RouterStatus:
def config(self) -> 'RouterConfig':
return self._config

@property
def version(self) -> int:
return self._version

@classmethod
def list(cls) -> List['Router']:
"""
Expand Down Expand Up @@ -128,7 +135,8 @@ def update(self, config: RouterConfig) -> 'Router':
Update the current router with a new set of configs specified in the RouterConfig argument

:param config: configuration of router
:return: instance of router updated (self)
:return: instance of router (self); this router contains details of the currently deployed router; it contains
the details of the currently DEPLOYED router version
deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
"""
self._config = config
updated_router = Router.from_open_api(
Expand Down Expand Up @@ -201,11 +209,13 @@ def get_events(self) -> List[turing.generated.models.Event]:
def wait_for_status(self, status: RouterStatus, max_tries: int = 15, duration: float = 10.0):
for i in range(1, max_tries + 1):
logger.debug(f"Checking if router {self.id} is {status.value}...")
cur_status = Router.get(self.id).status
current_router = Router.get(self.id)
cur_status = current_router.status
if cur_status == status:
# Wait for backend components to fully resolve
time.sleep(5)
logger.debug(f"Router {self.id} is finally {status.value}.")
self.__dict__ = current_router.__dict__
return
else:
logger.debug(f"Router {self.id} is {cur_status.value}.")
Expand Down