Skip to content

Commit 585e298

Browse files
committed
Add task cancel method
1 parent 3daa25b commit 585e298

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,3 +2339,26 @@ def get_task_by_id(self, task_id: str) -> Union[Task, DataUpsertTask]:
23392339

23402340
task._user = user
23412341
return task
2342+
2343+
def cancel_task(self, task_id: str) -> bool:
2344+
"""
2345+
Cancels a task with the given ID.
2346+
2347+
Args:
2348+
task_id (str): The ID of the task to cancel.
2349+
2350+
Returns:
2351+
bool: True if the task was successfully cancelled.
2352+
2353+
Raises:
2354+
LabelboxError: If the task could not be cancelled.
2355+
"""
2356+
mutation_str = """
2357+
mutation CancelTaskPyApi($id: ID!) {
2358+
cancelBulkOperationJob(id: $id) {
2359+
success
2360+
}
2361+
}
2362+
"""
2363+
res = self.execute(mutation_str, {"id": task_id})
2364+
return res["cancelBulkOperationJob"]["success"]

0 commit comments

Comments
 (0)