Skip to content

Commit

Permalink
Added delete task API. (#127)
Browse files Browse the repository at this point in the history
Function accepts task id and performs deleting.

Signed-off-by: Nurlan <nabzalbekov0@gmail.com>
  • Loading branch information
Nurlanprog authored Mar 30, 2023
1 parent 981bd8b commit 2c73825
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,20 @@ def delete_model(self, model_id: str) -> object:
method="DELETE",
url=API_URL,
)

def delete_task(self, task_id: str) -> object:
"""
This method deletes a task from opensearch cluster (using ml commons api)
:param task_id: unique id of the task
:type task_id: string
:return: returns a json object, with detailed information about the deleted task
:rtype: object
"""

API_URL = f"{ML_BASE_URI}/tasks/{task_id}"

return self._client.transport.perform_request(
method="DELETE",
url=API_URL,
)
7 changes: 7 additions & 0 deletions tests/ml_commons/test_ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ def test_integration_model_train_upload_full_cycle():
raised == False
), "Raised Exception in generating sentence embedding"

try:
delete_task_obj = ml_client.delete_task(task_id)
assert delete_task_obj.get("result") == "deleted"
except: # noqa: E722
raised = True
assert raised == False, "Raised Exception in deleting task"

try:
ml_client.unload_model(model_id)
for i in range(int(UNLOAD_TIMEOUT / 10)):
Expand Down

0 comments on commit 2c73825

Please sign in to comment.