Skip to content

Commit

Permalink
chore(resources): add silent option to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
heiruwu committed May 9, 2024
1 parent 82a41be commit 7eea8c3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
30 changes: 17 additions & 13 deletions instill/resources/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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):
Expand Down
38 changes: 26 additions & 12 deletions instill/resources/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -59,36 +63,46 @@ 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:
Logger.w(rpc_error.code())
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)

0 comments on commit 7eea8c3

Please sign in to comment.