Skip to content

Commit 790bfcf

Browse files
authored
PS-13958 Improve job management (#214)
* Adding ability to list and restart jobs
1 parent b5c758b commit 790bfcf

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ All notable changes to the `python-domino` library will be documented in this fi
88

99
### Changed
1010

11+
## 1.4.5
12+
13+
### Added
14+
* PS-13958 `jobs_list()` function lists recent jobs in a project
15+
* PS-13958 `job_restart()` function allows re-running a previous job
16+
17+
### Changed
18+
1119
## 1.4.4
1220

1321
### Added

README.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,26 @@ Stop the Job (execution) in the project.
593593
* _job_id (string):_ Job identifier.
594594
* _commit_results (boolean):_ (Defaults to `true`) If `false`, the job results are not committed.
595595

596+
==== jobs_list(project_id, page_size=None):
597+
598+
Lists job history for a given project_id
599+
600+
* _project_id (string):_ The project to query.
601+
* _page_size (string):_ How many results to return (default: 3).
602+
596603
==== job_status(job_id):
597604

598605
Get the status of a job.
599606

600607
* _job_id (string):_ Job identifier.
601608

609+
==== job_restart(job_id, should_use_original_input_commit=True):
610+
611+
Restart a previous job
612+
613+
* _job_id (string):_ ID of the original job. This can be obtained with `jobs_list()`.
614+
* _should_use_original_input_commit (bool):_ Should the new job run use the original code, or the current version?
615+
602616
==== job_start_blocking(poll_freq=5, max_poll_time=6000, **kwargs):
603617

604618
Start a job and poll until the job is finished.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,28 @@ Stop the Job (execution) in the project.
604604
- *commit_results (boolean):* (Defaults to `true`) If `false`, the
605605
job results are not committed.
606606

607+
### jobs_list(project_id, page_size=None):
608+
609+
Lists job history for a given project_id
610+
611+
- *project_id (string):* The project to query.
612+
613+
- *page_size (string):* How many results to return (default: 3).
614+
607615
### job_status(job_id):
608616

609617
Get the status of a job.
610618

611619
- *job_id (string):* Job identifier.
612620

621+
### job_restart(job_id, should_use_original_input_commit=True):
622+
623+
Restart a previous job
624+
625+
- *job_id (string):* ID of the original job. This can be obtained with `jobs_list()`.
626+
627+
- *should_use_original_input_commit (bool):* Should the new job run use the original code, or the current version?
628+
613629
### job_start_blocking(poll_freq=5, max_poll_time=6000, \*\*kwargs):
614630

615631
Start a job and poll until the job is finished. Additionally, this

domino/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.4.4"
1+
__version__ = "1.4.5"

domino/domino.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,17 @@ def job_stop(self, job_id: str, commit_results: bool = True):
617617
response = self.request_manager.post(url, json=request)
618618
return response
619619

620+
def jobs_list(self, project_id: str, page_size=None):
621+
"""
622+
Lists job history for a given project_id
623+
:param project_id: The project to query
624+
:param page_size: The number of jobs to return (default: 3)
625+
:return: The details
626+
"""
627+
url = self._routes.jobs_list(project_id, page_size)
628+
return self._get(url)
629+
630+
620631
def job_status(self, job_id: str) -> dict:
621632
"""
622633
Gets the status of job with given job_id
@@ -625,6 +636,24 @@ def job_status(self, job_id: str) -> dict:
625636
"""
626637
return self.request_manager.get(self._routes.job_status(job_id)).json()
627638

639+
def job_restart(
640+
self,
641+
job_id:str,
642+
should_use_original_input_commit: bool = True
643+
):
644+
"""
645+
Restarts a previous job
646+
:param job_id: ID of the original job that should be restarted
647+
:param should_use_original_input_commit: Should the new job run use the original code, or the current version?
648+
"""
649+
url = self._routes.job_restart()
650+
request = {
651+
"jobId": job_id,
652+
"shouldUseOriginalInputCommit": should_use_original_input_commit
653+
}
654+
response = self.request_manager.post(url, json=request)
655+
return response
656+
628657
def job_runtime_execution_details(self, job_id: str) -> dict:
629658
"""
630659
Gets the runtime execution details of job with given job_id

domino/routes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ def job_start(self):
175175
def job_stop(self):
176176
return f"{self.host}/v4/jobs/stop"
177177

178+
def jobs_list(self, project_id, page_size: Optional[str]):
179+
page_size_query = f"&page_size={page_size}" if page_size else ""
180+
return f"{self.host}/v4/jobs?projectId={project_id}{page_size_query}"
181+
178182
def job_status(self, job_id):
179183
return f"{self.host}/v4/jobs/{job_id}"
180184

185+
def job_restart(self):
186+
return f"{self.host}/v4/jobs/restart"
187+
181188
def job_runtime_execution_details(self, job_id):
182189
return f"{self.host}/v4/jobs/{job_id}/runtimeExecutionDetails"
183190

0 commit comments

Comments
 (0)