Skip to content

Commit 4e3f023

Browse files
committed
Update cancel_task to add clear unique_id option
1 parent b59920f commit 4e3f023

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

scaleapi/__init__.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ def get_task(self, task_id: str) -> Task:
6464
endpoint = f"task/{task_id}"
6565
return Task(self.api.get_request(endpoint), self)
6666

67-
def cancel_task(self, task_id: str) -> Task:
67+
def cancel_task(self, task_id: str, clear_unique_id=False) -> Task:
6868
"""Cancels a task and returns the associated task.
6969
Raises a ScaleException if it has already been canceled.
7070
7171
Args:
7272
task_id (str):
7373
Task id
74-
74+
clear_unique_id (boolean):
75+
Option to clear unique id when the task is deleted
7576
Returns:
7677
Task
7778
"""
78-
endpoint = f"task/{task_id}/cancel"
79+
if clear_unique_id:
80+
endpoint = f"task/{task_id}/cancel?clear_unique_id=true"
81+
else:
82+
endpoint = f"task/{task_id}/cancel"
7983
return Task(self.api.post_request(endpoint), self)
8084

8185
def tasks(self, **kwargs) -> Tasklist:
@@ -792,11 +796,7 @@ def import_file(self, file_url: str, **kwargs) -> File:
792796
filedata = self.api.post_request(endpoint, body=payload)
793797
return File(filedata, self)
794798

795-
def create_evaluation_task(
796-
self,
797-
task_type: TaskType,
798-
**kwargs,
799-
) -> EvaluationTask:
799+
def create_evaluation_task(self, task_type: TaskType, **kwargs,) -> EvaluationTask:
800800
"""This method can only be used for Rapid projects.
801801
Supported Task Types: [
802802
DocumentTranscription,
@@ -833,11 +833,7 @@ def create_evaluation_task(
833833
evaluation_task_data = self.api.post_request(endpoint, body=kwargs)
834834
return EvaluationTask(evaluation_task_data, self)
835835

836-
def create_training_task(
837-
self,
838-
task_type: TaskType,
839-
**kwargs,
840-
) -> TrainingTask:
836+
def create_training_task(self, task_type: TaskType, **kwargs,) -> TrainingTask:
841837
"""This method can only be used for Rapid projects.
842838
Supported Task Types: [
843839
DocumentTranscription,

tests/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ def test_get_batches():
390390
def test_files_upload():
391391
with open("tests/test_image.png", "rb") as f:
392392
client.upload_file(
393-
file=f,
394-
project_name=TEST_PROJECT_NAME,
393+
file=f, project_name=TEST_PROJECT_NAME,
395394
)
396395

397396

0 commit comments

Comments
 (0)