Skip to content

Commit ca4d505

Browse files
committed
add no_fail mode to run job/scenario
1 parent 15fdb50 commit ca4d505

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

dataikuapi/dss/project.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def start_job(self, definition):
279279
job_def = self.client._perform_json("POST", "/projects/%s/jobs/" % self.project_key, body = definition)
280280
return DSSJob(self.client, self.project_key, job_def['id'])
281281

282-
def start_job_and_wait(self, definition):
282+
def start_job_and_wait(self, definition, no_fail=False):
283283
"""
284284
Create a new job. Wait the end of the job to complete.
285285
@@ -298,8 +298,11 @@ def start_job_and_wait(self, definition):
298298
time.sleep(sleep_time)
299299
job_state = job.get_status().get("baseStatus", {}).get("state", "")
300300
if job_state in ["ABORTED", "FAILED"]:
301-
raise DataikuException("Job run did not finish. Status: %s" % (job_state))
302-
301+
if no_fail:
302+
break
303+
else:
304+
raise DataikuException("Job run did not finish. Status: %s" % (job_state))
305+
return job_state
303306

304307
########################################################
305308
# Variables

dataikuapi/dss/scenario.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_trigger_fire(self, trigger_id, trigger_run_id):
4646
})
4747
return DSSTriggerFire(self, trigger_fire)
4848

49-
def run_and_wait(self, params={}):
49+
def run_and_wait(self, params={}, no_fail=False):
5050
"""
5151
Requests a run of the scenario, which will start after a few seconds. Wait the end of the run to complete.
5252
@@ -64,7 +64,10 @@ def run_and_wait(self, params={}):
6464
if refresh_trigger_counter == 10:
6565
refresh_trigger_counter = 0
6666
if trigger_fire.is_cancelled(refresh=refresh_trigger_counter == 0):
67-
raise DataikuException("Scenario run has been cancelled")
67+
if no_fail:
68+
return None
69+
else:
70+
raise DataikuException("Scenario run has been cancelled")
6871
scenario_run = trigger_fire.get_scenario_run()
6972
time.sleep(5)
7073
while not scenario_run.run.get('result', False):

0 commit comments

Comments
 (0)