From 7eea8c359839e33c0bf4f9a3a89dc978897c28c8 Mon Sep 17 00:00:00 2001 From: Heiru Wu Date: Thu, 9 May 2024 13:13:05 +0800 Subject: [PATCH] chore(resources): add silent option to resource --- instill/resources/model.py | 30 +++++++++++++++------------ instill/resources/pipeline.py | 38 ++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/instill/resources/model.py b/instill/resources/model.py index 1e153d4..7f849fc 100644 --- a/instill/resources/model.py +++ b/instill/resources/model.py @@ -47,7 +47,7 @@ def __init__( self.resource = model - def __call__(self, task_inputs: list) -> list: + def __call__(self, task_inputs: list, silent: bool = False) -> list: return self.client.model_service.trigger_model( self.resource.id, task_inputs ).task_outputs @@ -76,15 +76,17 @@ def _update(self): def get_definition(self) -> model_definition_interface.ModelDefinition: return self.resource.model_definition - def get_readme(self) -> str: - return self.client.model_service.get_model_card(self.resource.id).readme + def get_readme(self, silent: bool = False) -> str: + return self.client.model_service.get_model_card(self.resource.id, silent).readme - def get_state(self) -> model_interface.Model.State: - return self.client.model_service.watch_model(self.resource.id).state + def get_state(self, silent: bool = False) -> model_interface.Model.State: + return self.client.model_service.watch_model(self.resource.id, silent).state - def deploy(self) -> model_interface.Model.State: - self.client.model_service.deploy_model(self.resource.id) - state = self.client.model_service.watch_model(model_name=self.resource.id).state + def deploy(self, silent: bool = False) -> model_interface.Model.State: + self.client.model_service.deploy_model(self.resource.id, silent) + state = self.client.model_service.watch_model( + model_name=self.resource.id, silent=silent + ).state while state not in (2, 3): time.sleep(1) state = self.client.model_service.watch_model( @@ -93,9 +95,11 @@ def deploy(self) -> model_interface.Model.State: self._update() return state - def undeploy(self) -> model_interface.Model.State: - self.client.model_service.undeploy_model(self.resource.id) - state = self.client.model_service.watch_model(model_name=self.resource.id).state + def undeploy(self, silent: bool = False) -> model_interface.Model.State: + self.client.model_service.undeploy_model(self.resource.id, silent) + state = self.client.model_service.watch_model( + model_name=self.resource.id, silent=silent + ).state while state not in (1, 3): time.sleep(1) state = self.client.model_service.watch_model( @@ -104,9 +108,9 @@ def undeploy(self) -> model_interface.Model.State: self._update() return state - def delete(self): + def delete(self, silent: bool = False): if self.resource is not None: - self.client.model_service.delete_model(self.resource.id) + self.client.model_service.delete_model(self.resource.id, silent) class GithubModel(Model): diff --git a/instill/resources/pipeline.py b/instill/resources/pipeline.py index a86e13a..9fbc58c 100644 --- a/instill/resources/pipeline.py +++ b/instill/resources/pipeline.py @@ -33,10 +33,14 @@ def __init__( self.resource = pipeline def __call__( - self, task_inputs: list + self, + task_inputs: list, + silent: bool, ) -> Tuple[list, pipeline_interface.TriggerMetadata]: resp = self.client.pipeline_service.trigger_pipeline( - self.resource.id, task_inputs + self.resource.id, + task_inputs, + silent, ) return resp.outputs, resp.metadata @@ -59,29 +63,39 @@ def resource(self, resource: pipeline_interface.Pipeline): def _update(self): self.resource = self.client.pipeline_service.get_pipeline(name=self.resource.id) - def get_operation(self, operation: operations_pb2.Operation): - return self.client.pipeline_service.get_operation(operation.name).operation + def get_operation(self, operation: operations_pb2.Operation, silent: bool = False): + return self.client.pipeline_service.get_operation( + operation.name, silent + ).operation - def trigger_async(self, task_inputs: list) -> operations_pb2.Operation: + def trigger_async( + self, + task_inputs: list, + silent: bool = False, + ) -> operations_pb2.Operation: return self.client.pipeline_service.trigger_async_pipeline( - self.resource.id, task_inputs + self.resource.id, + task_inputs, + silent, ).operation def get_recipe(self) -> pipeline_interface.Recipe: return self.resource.recipe - def update_recipe(self, recipe: pipeline_interface.Recipe): + def update_recipe(self, recipe: pipeline_interface.Recipe, silent: bool = False): pipeline = self.resource pipeline.recipe.CopyFrom(recipe) self.client.pipeline_service.update_pipeline( - pipeline, FieldMask(paths=["recipe"]) + pipeline, + FieldMask(paths=["recipe"]), + silent, ) self._update() - def validate_pipeline(self) -> bool: + def validate_pipeline(self, silent: bool = True) -> bool: try: self.client.pipeline_service.validate_pipeline( - name=self.resource.id, silent=True + name=self.resource.id, silent=silent ) return True except grpc.RpcError as rpc_error: @@ -89,6 +103,6 @@ def validate_pipeline(self) -> bool: Logger.w(rpc_error.details()) return False - def delete(self): + def delete(self, silent: bool = False): if self.resource is not None: - self.client.pipeline_service.delete_pipeline(self.resource.id) + self.client.pipeline_service.delete_pipeline(self.resource.id, silent)