Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions labelbox/schema/task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import requests
import time
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -31,6 +32,7 @@ class Task(DbObject):
name = Field.String("name")
status = Field.String("status")
completion_percentage = Field.Float("completion_percentage")
result = Field.String("result")
_user: Optional["User"] = None

# Relationships
Expand Down Expand Up @@ -65,3 +67,13 @@ def wait_till_done(self, timeout_seconds=300) -> None:
timeout_seconds -= check_frequency
time.sleep(sleep_time_seconds)
self.refresh()

def errors(self):
""" Downloads the result file from Task
"""
if self.status == "FAILED" and self.result:
response = requests.get(self.result)
response.raise_for_status()
data = response.json()
return data.get('error')
return None
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ ignore_missing_imports = True
ignore_errors = True

[mypy-labelbox]
ignore_errors = True
ignore_errors = True
39 changes: 39 additions & 0 deletions tests/integration/test_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from labelbox import DataRow
from labelbox.schema.data_row_metadata import DataRowMetadataField

EMBEDDING_SCHEMA_ID = "ckpyije740000yxdk81pbgjdc"


def test_task_errors(dataset, image_url):
client = dataset.client
embeddings = [0.0] * 128
task = dataset.create_data_rows([
{
DataRow.row_data:
image_url,
DataRow.metadata_fields: [
DataRowMetadataField(schema_id=EMBEDDING_SCHEMA_ID,
value=embeddings),
DataRowMetadataField(schema_id=EMBEDDING_SCHEMA_ID,
value=embeddings)
]
},
])
assert task in client.get_user().created_tasks()
task.wait_till_done()
assert task.status == "FAILED"
assert task.errors() is not None
assert 'message' in task.errors()


def test_task_success(dataset, image_url):
client = dataset.client
task = dataset.create_data_rows([
{
DataRow.row_data: image_url,
},
])
assert task in client.get_user().created_tasks()
task.wait_till_done()
assert task.status == "COMPLETE"
assert task.errors() is None