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

Options
etienne_95
etienne_95 Registered Posts: 4 ✭✭✭✭

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

Answers

  • Clément_Stenac
    Clément_Stenac Dataiker, Dataiku DSS Core Designer, Registered Posts: 753 Dataiker
    Options

    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

  • etienne_95
    etienne_95 Registered Posts: 4 ✭✭✭✭
    Options

    Merci Clément pour ces infos !

Setup Info
    Tags
      Help me…