python code to check whether a dash webapp backend is running

Options
jurriaann
jurriaann Registered Posts: 6

Hi! I have a dash webapp running. I would like to be able to check whether the webapp backend is still running , so that I can restart it with a scenario if it has stopped . Dataiku scenarios do support (re)starting webapp backends, but I can't find how to check if it stopped running yeyt. Is this possible and does anyone have some example (python) code? Many thanks!

Answers

  • Sarina
    Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 315 Dataiker
    Options

    Hi @jurriaann
    ,

    Webapp endpoints are not available through the Python API for the most part, but are available through the REST API. You can use this combined with the Python API to pretty easily get the webapp backend status for any webapps.

    Here is an example to check if any webapps within a project are running.

    import dataikufrom dataiku import pandasutils as pduimport pandas as pdimport requestsimport jsonfrom requests.auth import HTTPBasicAuthclient = dataiku.api_client()dss_host = "REPLACE_WITH_DSS_HOST" # ends with slash, http://yourdsshost:port/api_key = "REPLACE_WITH_DSS_API_KEY" # something like XcmNkXx8NJjMZIFd2aWpshHIfzJ8btVjbase_url = '/public/api/projects'project_key = client.get_default_project().project_keyendpoint = "public/api/projects/" + project_key + "/webapps/"response = requests.get(dss_host + endpoint, auth=HTTPBasicAuth(api_key, ''))if response.status_code == 200:print(response.json()) # if you want to take a look at the responsefor webapp in response.json():if webapp['backendRunning']:print('Do stuff to running webapp ', webapp['id'])else:print(response.reason)

    I hope that's helpful, let us know if you have any questions about this.

    Thanks,
    Sarina

  • jurriaann
    jurriaann Registered Posts: 6
    Options

    Thanks @SarinaS
    !! Very helpfull, good to know I can check the status of a webapp this way.

    For others with similar question: My admin pointed out to me that Dataiku also has a feature for webapps, that enable auto-start Webapp (see picture below) that apparently restarts the webapp each time dataiku is restarted! I didn't know that, and will try that one.

    Again, thanks for the code, it will probably be usefull to me (or others) in the future for other use cases.

  • CoreyS
    CoreyS Dataiker Alumni, Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Registered Posts: 1,150 ✭✭✭✭✭✭✭✭✭
    Options

    Thank you for sharing some of that juicy knowledge with the rest of the Community @jurriaann
    !

  • Sarina
    Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 315 Dataiker
    Options

    Hi @jurriaann
    ,

    Thank you for the update! Indeed if "Auto-start backend" meets your use case, this is definitely a much simpler approach Sarina

Setup Info
    Tags
      Help me…