Skip to content

Commit a753646

Browse files
Merge pull request #697 from Labelbox/kkim/task-result-improve
[AL-0] Improve task result to include globalKeys and throw warning
2 parents a71a2f1 + 7487d44 commit a753646

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Introduces `Project.queue_mode` as an optional parameter when creating projects
1010
* `MEAToMALPredictionImport` class
1111
* This allows users to use predictions stored in Models for MAL
12+
* `Task.wait_till_done` now shows a warning if task has failed
1213
### Changed
1314
* Increase scalar metric value limit to 100m
1415
* Added deprecation warnings when updating project `queue_mode`

labelbox/schema/task.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def wait_till_done(self, timeout_seconds=300) -> None:
6464
check_frequency = 2 # frequency of checking, in seconds
6565
while True:
6666
if self.status != "IN_PROGRESS":
67+
if self.status == 'FAILED':
68+
logger.warning(
69+
"There are errors present. Please look at `task.errors` for more details"
70+
)
6771
return
6872
sleep_time_seconds = min(check_frequency, timeout_seconds)
6973
logger.debug("Task.wait_till_done sleeping for %.2f seconds" %
@@ -94,24 +98,32 @@ def result(self) -> List[Dict[str, Any]]:
9498
return [{
9599
'id': data_row['id'],
96100
'external_id': data_row.get('externalId'),
97-
'row_data': data_row['rowData']
101+
'row_data': data_row['rowData'],
102+
'global_key': data_row.get('globalKey'),
98103
} for data_row in result['createdDataRows']]
99104

100105
@lru_cache()
101106
def _fetch_remote_json(self) -> Dict[str, Any]:
102107
""" Function for fetching and caching the result data.
103108
"""
109+
110+
def download_result():
111+
response = requests.get(self.result_url)
112+
response.raise_for_status()
113+
return response.json()
114+
104115
if self.name != 'JSON Import':
105116
raise ValueError(
106117
"Task result is only supported for `JSON Import` tasks."
107118
" Download task.result_url manually to access the result for other tasks."
108119
)
109-
self.wait_till_done(timeout_seconds=600)
110-
if self.status == "IN_PROGRESS":
111-
raise ValueError(
112-
"Job status still in `IN_PROGRESS`. The result is not available. Call task.wait_till_done() with a larger timeout or contact support."
113-
)
114120

115-
response = requests.get(self.result_url)
116-
response.raise_for_status()
117-
return response.json()
121+
if self.status != "IN_PROGRESS":
122+
return download_result()
123+
else:
124+
self.wait_till_done(timeout_seconds=600)
125+
if self.status == "IN_PROGRESS":
126+
raise ValueError(
127+
"Job status still in `IN_PROGRESS`. The result is not available. Call task.wait_till_done() with a larger timeout or contact support."
128+
)
129+
return download_result()

0 commit comments

Comments
 (0)