Skip to content

Commit 01f1e93

Browse files
author
Bihan Jiang
committed
add status, type, and creation time to async job
1 parent e87be02 commit 01f1e93

File tree

6 files changed

+63
-31
lines changed

6 files changed

+63
-31
lines changed

nucleus/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
ERROR_ITEMS,
8787
ERROR_PAYLOAD,
8888
ERRORS_KEY,
89+
JOB_ID_KEY,
90+
JOB_STATUS_KEY,
91+
JOB_TYPE_KEY,
92+
JOB_CREATION_TIME_KEY,
8993
IMAGE_KEY,
9094
IMAGE_URL_KEY,
9195
ITEM_METADATA_SCHEMA_KEY,
@@ -110,7 +114,7 @@
110114
NotFoundError,
111115
NucleusAPIError,
112116
)
113-
from .job import Job
117+
from .job import AsyncJob
114118
from .model import Model
115119
from .model_run import ModelRun
116120
from .payload_constructor import (
@@ -200,19 +204,21 @@ def list_datasets(self) -> Dict[str, Union[str, List[str]]]:
200204
"""
201205
return self.make_request({}, "dataset/", requests.get)
202206

203-
def list_jobs(self, show_completed=None, date_limit=None) -> List[Job]:
207+
def list_jobs(
208+
self, show_completed=None, date_limit=None
209+
) -> List[AsyncJob]:
204210
"""
205211
Lists jobs for user.
206212
:return: jobs
207213
"""
208214
payload = {show_completed: show_completed, date_limit: date_limit}
209215
job_objects = self.make_request(payload, "jobs/", requests.get)
210216
return [
211-
Job(
212-
job_id=job["job_id"],
213-
job_status=["job_status"],
214-
job_type=["job_type"],
215-
job_creation_time=["job_creation_time"],
217+
AsyncJob(
218+
job_id=job[JOB_ID_KEY],
219+
job_status=job[JOB_STATUS_KEY],
220+
job_type=job[JOB_TYPE_KEY],
221+
job_creation_time=job[JOB_CREATION_TIME_KEY],
216222
client=self,
217223
)
218224
for job in job_objects

nucleus/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
ITEM_METADATA_SCHEMA_KEY = "item_metadata_schema"
4343
JOB_ID_KEY = "job_id"
4444
KEEP_HISTORY_KEY = "keep_history"
45+
JOB_STATUS_KEY = "job_last_known_status"
46+
JOB_TYPE_KEY = "job_type"
47+
JOB_CREATION_TIME_KEY = "job_creation_time"
4548
LABEL_KEY = "label"
4649
MASK_URL_KEY = "mask_url"
4750
MESSAGE_KEY = "message"

nucleus/dataset.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
DEFAULT_ANNOTATION_UPDATE_MODE,
2525
EXPORTED_ROWS,
2626
JOB_ID_KEY,
27+
JOB_STATUS_KEY,
28+
JOB_TYPE_KEY,
29+
JOB_CREATION_TIME_KEY,
2730
NAME_KEY,
2831
REFERENCE_IDS_KEY,
2932
REQUEST_ID_KEY,
@@ -182,7 +185,13 @@ def annotate(
182185
route=f"dataset/{self.id}/annotate?async=1",
183186
)
184187

185-
return AsyncJob(response[JOB_ID_KEY], self._client)
188+
return AsyncJob(
189+
response[JOB_ID_KEY],
190+
response[JOB_STATUS_KEY],
191+
response[JOB_TYPE_KEY],
192+
response[JOB_CREATION_TIME_KEY],
193+
self._client,
194+
)
186195

187196
return self._client.annotate_dataset(
188197
self.id, annotations, update=update, batch_size=batch_size
@@ -241,7 +250,13 @@ def append(
241250
payload={REQUEST_ID_KEY: request_id, UPDATE_KEY: update},
242251
route=f"dataset/{self.id}/append?async=1",
243252
)
244-
return AsyncJob(response[JOB_ID_KEY], self._client)
253+
return AsyncJob(
254+
response[JOB_ID_KEY],
255+
response[JOB_STATUS_KEY],
256+
response[JOB_TYPE_KEY],
257+
response[JOB_CREATION_TIME_KEY],
258+
self._client,
259+
)
245260

246261
return self._client.populate_dataset(
247262
self.id,

nucleus/job.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@
99

1010
@dataclass
1111
class AsyncJob:
12-
id: str
12+
job_id: str
13+
job_status: str
14+
job_type: str
15+
job_creation_time: str
1316
client: "NucleusClient" # type: ignore # noqa: F821
1417

1518
def status(self) -> Dict[str, str]:
1619
return self.client.make_request(
1720
payload={},
18-
route=f"job/{self.id}",
21+
route=f"job/{self.job_id}",
1922
requests_command=requests.get,
2023
)
2124

2225
def errors(self) -> List[str]:
2326
return self.client.make_request(
2427
payload={},
25-
route=f"job/{self.id}/errors",
28+
route=f"job/{self.job_id}/errors",
2629
requests_command=requests.get,
2730
)
2831

@@ -43,22 +46,6 @@ def sleep_until_complete(self, verbose_std_out=True):
4346
raise JobError(final_status, self)
4447

4548

46-
class Job:
47-
def __init__(
48-
self,
49-
job_id,
50-
job_status,
51-
job_type,
52-
job_creation_time,
53-
client,
54-
) -> None:
55-
self.job_id = job_id
56-
self.job_status = job_status
57-
self.job_type = job_type
58-
self.job_creation_type = job_creation_time
59-
self._client = client
60-
61-
6249
class JobError(Exception):
6350
def __init__(self, job_status: Dict[str, str], job: AsyncJob):
6451
final_status_message = job_status["message"]

nucleus/model_run.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
BOX_TYPE,
1010
DEFAULT_ANNOTATION_UPDATE_MODE,
1111
JOB_ID_KEY,
12+
JOB_STATUS_KEY,
13+
JOB_TYPE_KEY,
14+
JOB_CREATION_TIME_KEY,
1215
POLYGON_TYPE,
1316
REQUEST_ID_KEY,
1417
SEGMENTATION_TYPE,
@@ -116,7 +119,13 @@ def predict(
116119
route=f"modelRun/{self.model_run_id}/predict?async=1",
117120
)
118121

119-
return AsyncJob(response[JOB_ID_KEY], self._client)
122+
return AsyncJob(
123+
response[JOB_ID_KEY],
124+
response[JOB_STATUS_KEY],
125+
response[JOB_TYPE_KEY],
126+
response[JOB_CREATION_TIME_KEY],
127+
self._client,
128+
)
120129
else:
121130
return self._client.predict(self.model_run_id, annotations, update)
122131

nucleus/slice.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from nucleus.dataset_item import DatasetItem
77
from nucleus.job import AsyncJob
88
from nucleus.utils import convert_export_payload, format_dataset_item_response
9-
from nucleus.constants import EXPORTED_ROWS
9+
from nucleus.constants import (
10+
EXPORTED_ROWS,
11+
JOB_ID_KEY,
12+
JOB_STATUS_KEY,
13+
JOB_TYPE_KEY,
14+
JOB_CREATION_TIME_KEY,
15+
)
1016

1117

1218
class Slice:
@@ -122,7 +128,13 @@ def send_to_labeling(self, project_id: str):
122128
response = self._client.make_request(
123129
{}, f"slice/{self.slice_id}/{project_id}/send_to_labeling"
124130
)
125-
return AsyncJob(response["job_id"], self._client)
131+
return AsyncJob(
132+
response[JOB_ID_KEY],
133+
response[JOB_STATUS_KEY],
134+
response[JOB_TYPE_KEY],
135+
response[JOB_CREATION_TIME_KEY],
136+
self._client,
137+
)
126138

127139

128140
def check_annotations_are_in_slice(

0 commit comments

Comments
 (0)