Skip to content

Commit 959640b

Browse files
committed
More scenario API details
1 parent b96e2d6 commit 959640b

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

dataikuapi/dss/scenario.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def run(self, params=None):
5252

5353
def get_last_runs(self, limit=10, only_finished_runs=False):
5454
"""
55-
Get the list of the last runs of the scenario.
55+
Get the list of the last runs of the scenario
5656
5757
:return: A list of :class:`dataikuapi.dss.scenario.DSSScenarioRun`
5858
"""
@@ -65,14 +65,24 @@ def get_last_runs(self, limit=10, only_finished_runs=False):
6565

6666
def get_last_finished_run(self):
6767
"""
68-
Gets the last run that completed (either successfully or not)
68+
Gets the last run that completed (successfully or not)
6969
:return: A :class:`dataikuapi.dss.scenario.DSSScenarioRun`
7070
"""
71-
lr = self.get_last_runs(only_finished_runs=True)
71+
lr = [sr for sr in self.get_last_runs() if not sr.running]
7272
if len(lr) == 0:
7373
raise ValueError("No scenario run completed")
7474
return lr[0]
7575

76+
def get_last_successful_run(self):
77+
"""
78+
Gets the last run that completed successfully
79+
:return: A :class:`dataikuapi.dss.scenario.DSSScenarioRun`
80+
"""
81+
lr = self.get_last_runs(only_finished_runs=True)
82+
if len(lr) == 0:
83+
raise ValueError("No scenario run completed successfully")
84+
return lr[0]
85+
7686
def get_current_run(self):
7787
"""
7888
Get the current run of the scenario, or None if it is not running at the moment
@@ -485,6 +495,18 @@ def steps(self):
485495
def last_step(self):
486496
return self["stepRuns"][len(self["stepRuns"]) - 1]
487497

498+
@property
499+
def first_error_details(self):
500+
"""
501+
Try to get the details of the first error if this run failed. This will not always be able
502+
to find the error details (it returns None in that case)
503+
"""
504+
for step in self.steps:
505+
step_error = step.first_error_details
506+
if step_error is not None:
507+
return step_error
508+
509+
488510
class DSSStepRunDetails(dict):
489511
def __init__(self, data):
490512
super(DSSStepRunDetails, self).__init__(data)
@@ -498,6 +520,23 @@ def job_ids(self):
498520
"""The list of DSS job ids that were ran as part of this step"""
499521
return [ri["jobId"] for ri in self["additionalReportItems"] if ri["type"] == "JOB_EXECUTED"]
500522

523+
@property
524+
def first_error_details(self):
525+
"""
526+
Try to get the details of the first error if this step failed. This will not always be able
527+
to find the error details (it returns None in that case)
528+
"""
529+
if self.outcome == 'FAILED':
530+
step_thrown = self.get('result').get('thrown', None)
531+
if step_thrown is not None:
532+
return step_thrown
533+
534+
for item in self['additionalReportItems']:
535+
if item.get("outcome", None) == 'FAILED':
536+
item_thrown = item.get('thrown', None)
537+
if item_thrown is not None:
538+
return item_thrown
539+
501540
class DSSScenarioRunWaiter(object):
502541
"""
503542
Helper to wait for a scenario to run to complete

0 commit comments

Comments
 (0)