Skip to content

Commit e87be02

Browse files
author
Bihan Jiang
committed
add list_jobs to nucleus-python-client api
1 parent a876e89 commit e87be02

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ dataset = client.create_dataset("My Dataset")
5050
```python
5151
datasets = client.list_datasets()
5252
```
53-
53+
### List Jobs
54+
```python
55+
jobs = client.list_jobs()
56+
```
5457
### Delete a Dataset
5558

5659
By specifying target dataset id.

nucleus/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
NotFoundError,
111111
NucleusAPIError,
112112
)
113+
from .job import Job
113114
from .model import Model
114115
from .model_run import ModelRun
115116
from .payload_constructor import (
@@ -199,6 +200,24 @@ def list_datasets(self) -> Dict[str, Union[str, List[str]]]:
199200
"""
200201
return self.make_request({}, "dataset/", requests.get)
201202

203+
def list_jobs(self, show_completed=None, date_limit=None) -> List[Job]:
204+
"""
205+
Lists jobs for user.
206+
:return: jobs
207+
"""
208+
payload = {show_completed: show_completed, date_limit: date_limit}
209+
job_objects = self.make_request(payload, "jobs/", requests.get)
210+
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"],
216+
client=self,
217+
)
218+
for job in job_objects
219+
]
220+
202221
def get_dataset_items(self, dataset_id) -> List[DatasetItem]:
203222
"""
204223
Gets all the dataset items inside your repo as a json blob.

nucleus/job.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ def sleep_until_complete(self, verbose_std_out=True):
4343
raise JobError(final_status, self)
4444

4545

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+
4662
class JobError(Exception):
4763
def __init__(self, job_status: Dict[str, str], job: AsyncJob):
4864
final_status_message = job_status["message"]

0 commit comments

Comments
 (0)