Discover the winners & finalists of the 2022 Dataiku Frontrunner Awards!READ THEIR USE CASES

dataikuapi - python - run a scenario through api and get the status

etienne_95
Level 2
dataikuapi - python - run a scenario through api and get the status

Hi, 

Through this tutorial (https://doc.dataiku.com/dss/latest/python-api/scenarios.html#run-a-scenario), I manage to run a scenario. 

But I don't why I didn't manage to grab the status. I have an error message : "AttributeError: 'DSSScenario' object has no attribute 'running'"

 

def get_scenario(dss_project, dss_scenario, dss_timer😞
project = client.get_project(dss_project)
scenario = project.get_scenario(dss_scenario)
print("Scenario :" + str(scenario) )
trigger_fire = scenario.run()
scenario_run = trigger_fire.wait_for_scenario_run()
print(str(scenario.running))
while True:
# Do a bit of other stuff
# ...

scenario_run.refresh()
if scenario_run.running:
print("Scenario is still running ...")
else:
print("Scenario is not running anymore")
break

time.sleep(5)
if __name__ == "__main__":
print("-------------> Scenario Start <--------------")
DSS_host = sys.argv[1]
DSS_ApiKey = sys.argv[2]
DSS_ProjectKey = sys.argv[3]
Dss_Scenario = sys.argv[4]
Dss_TimeWaitForStatus = int(sys.argv[5])

client = dataikuapi.DSSClient(DSS_host, DSS_ApiKey)
get_scenario(DSS_ProjectKey, Dss_Scenario, Dss_TimeWaitForStatus)

If someone have an idea ? 

Best regards

Etienne SIGWALD

0 Kudos
2 Replies
Clément_Stenac
Dataiker

Hi,

There are two important things here.

First of all, indeed, there is no running attribute on the DSSScenario class. I.e. You cannot do scenario.running

There is however a running flag on the DSSScenarioStatus, obtained by calling scenario.get_status(), and there is also a running flag on the DSSScenarioRun, obtained as a result of scenario.run().wait_for_scenario_run or scenario.get_last_runs().

 

It's however important to note that this documentation is for DSS 8.0 - If you have an older version of DSS, the API was simpler and did not have these helpful helpers. You will find the previous API for DSS 7.0 here: https://doc.dataiku.com/dss/7.0/python-api/scenarios.html

0 Kudos
etienne_95
Level 2
Author

Merci Clément pour ces infos ! 

0 Kudos