|
| 1 | +import time |
1 | 2 | from dataset import DSSDataset |
2 | 3 | from recipe import DSSRecipe |
3 | 4 | from managedfolder import DSSManagedFolder |
|
9 | 10 | import os.path as osp |
10 | 11 | from .future import DSSFuture |
11 | 12 | from .notebook import DSSNotebook |
| 13 | +from dataikuapi.utils import DataikuException |
| 14 | + |
12 | 15 |
|
13 | 16 | class DSSProject(object): |
14 | 17 | """ |
@@ -276,6 +279,26 @@ def start_job(self, definition): |
276 | 279 | job_def = self.client._perform_json("POST", "/projects/%s/jobs/" % self.project_key, body = definition) |
277 | 280 | return DSSJob(self.client, self.project_key, job_def['id']) |
278 | 281 |
|
| 282 | + def start_job_and_wait(self, definition): |
| 283 | + """ |
| 284 | + Create a new job. Wait the end of the job to complete. |
| 285 | + |
| 286 | + Args: |
| 287 | + definition: the definition for the job to create. The definition must contain the type of job (RECURSIVE_BUILD, |
| 288 | + NON_RECURSIVE_FORCED_BUILD, RECURSIVE_FORCED_BUILD, RECURSIVE_MISSING_ONLY_BUILD) and a list of outputs to build. |
| 289 | + Optionally, a refreshHiveMetastore field can specify whether to re-synchronize the Hive metastore for recomputed |
| 290 | + HDFS datasets. |
| 291 | + """ |
| 292 | + job_def = self.client._perform_json("POST", "/projects/%s/jobs/" % self.project_key, body = definition) |
| 293 | + job = DSSJob(self.client, self.project_key, job_def['id']) |
| 294 | + job_state = job.get_status().get("baseStatus", {}).get("state", "") |
| 295 | + sleep_time = 2 |
| 296 | + while job_state not in ["DONE", "ABORTED", "FAILED"]: |
| 297 | + sleep_time = 300 if sleep_time >= 300 else sleep_time * 2 |
| 298 | + time.sleep(sleep_time) |
| 299 | + job_state = job.get_status().get("baseStatus", {}).get("state", "") |
| 300 | + if job_state in ["ABORTED", "FAILED"]: |
| 301 | + raise DataikuException("Job run did not finish. Status: %s" % (job_state)) |
279 | 302 |
|
280 | 303 |
|
281 | 304 | ######################################################## |
|
0 commit comments