Skip to content

Commit 08a82b3

Browse files
committed
Added stat_job_and_wait method in DSSProject
1 parent 43b73d6 commit 08a82b3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

dataikuapi/dss/project.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from dataset import DSSDataset
23
from recipe import DSSRecipe
34
from managedfolder import DSSManagedFolder
@@ -9,6 +10,8 @@
910
import os.path as osp
1011
from .future import DSSFuture
1112
from .notebook import DSSNotebook
13+
from dataikuapi.utils import DataikuException
14+
1215

1316
class DSSProject(object):
1417
"""
@@ -276,6 +279,26 @@ def start_job(self, definition):
276279
job_def = self.client._perform_json("POST", "/projects/%s/jobs/" % self.project_key, body = definition)
277280
return DSSJob(self.client, self.project_key, job_def['id'])
278281

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))
279302

280303

281304
########################################################

0 commit comments

Comments
 (0)