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
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions sdk/turing/router/config/experiment_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def config(self) -> Dict:

@config.setter
def config(self, config: Dict):
if config is not None and 'project_id' in config:
config['project_id'] = int(config['project_id'])
self._config = config
if self._config is not None and 'project_id' in self._config:
self.config['project_id'] = int(self._config['project_id'])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as the one I just commented on, though the fix here was to simply reorder the statements.


def to_open_api(self) -> OpenApiModel:
if self.config is None:
Expand Down
14 changes: 8 additions & 6 deletions sdk/turing/router/config/router_ensembler_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ def standard_config(self, standard_config: Union[turing.generated.models.Ensembl
if isinstance(standard_config, turing.generated.models.EnsemblerStandardConfig):
self._standard_config = standard_config
elif isinstance(standard_config, dict):
standard_config['experiment_mappings'] = [
openapi_standard_config = standard_config.copy()
openapi_standard_config['experiment_mappings'] = [
turing.generated.models.EnsemblerStandardConfigExperimentMappings(**mapping)
for mapping in standard_config['experiment_mappings']
]
self._standard_config = turing.generated.models.EnsemblerStandardConfig(**standard_config)
self._standard_config = turing.generated.models.EnsemblerStandardConfig(**openapi_standard_config)
else:
self._standard_config = standard_config

Expand All @@ -76,11 +77,12 @@ def docker_config(self, docker_config: turing.generated.models.EnsemblerDockerCo
if isinstance(docker_config, turing.generated.models.EnsemblerDockerConfig):
self._docker_config = docker_config
elif isinstance(docker_config, dict):
docker_config['resource_request'] = \
turing.generated.models.ResourceRequest(**docker_config['resource_request'])
docker_config['env'] = [turing.generated.models.EnvVar(**env_var) for env_var in docker_config['env']]
openapi_docker_config = docker_config.copy()
openapi_docker_config['resource_request'] = \
turing.generated.models.ResourceRequest(**openapi_docker_config['resource_request'])
openapi_docker_config['env'] = [turing.generated.models.EnvVar(**env_var) for env_var in openapi_docker_config['env']]
Copy link
Contributor Author

@deadlycoconuts deadlycoconuts Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some additional changes - they look pretty minor but they were causing some bugs in the unit tests after the refactoring suggested earlier.

Essentially, the previous implementation of the setter methods were mutating the dictionaries that were being passed to it as arguments, which is dangerous and might lead to unintended effects. These new changes simply create new working dictionaries that are only used within the scope of the setter.

cc @krithika369

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks for addressing them. We need to propagate these changes to main later as well.

self._docker_config = turing.generated.models.EnsemblerDockerConfig(
**docker_config
**openapi_docker_config
)
else:
self._docker_config = docker_config
Expand Down
18 changes: 10 additions & 8 deletions sdk/turing/router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def __init__(self,
self._endpoint = endpoint
self._monitoring_url = monitoring_url
self._status = RouterStatus(status)

if config is not None:
self._config = RouterConfig(name=name, environment_name=environment_name, **config)
else:
self._config = None
self._config = config

@property
def id(self) -> int:
Expand Down Expand Up @@ -80,7 +76,11 @@ def status(self) -> RouterStatus:

@property
def config(self) -> 'RouterConfig':
return self._config
return RouterConfig(name=self.name, environment_name=self.environment_name, **self._config)

@property
def version(self) -> int:
return self._config.get('version') if self._config else None

@classmethod
def list(cls) -> List['Router']:
Expand Down Expand Up @@ -128,7 +128,7 @@ 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 router and its currently deployed version
"""
self._config = config
updated_router = Router.from_open_api(
Expand Down Expand Up @@ -201,11 +201,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