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

python code to check whether a dash webapp backend is running

jurriaann
Level 1
python code to check whether a dash webapp backend is running

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!

0 Kudos
4 Replies
SarinaS
Dataiker

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 dataiku
from dataiku import pandasutils as pdu
import pandas as pd

import requests
import json 
from requests.auth import HTTPBasicAuth
client = dataiku.api_client()

dss_host = "REPLACE_WITH_DSS_HOST" # ends with slash, http://yourdsshost:port/
api_key = "REPLACE_WITH_DSS_API_KEY" # something like XcmNkXx8NJjMZIFd2aWpshHIfzJ8btVj

base_url = '/public/api/projects'

project_key = client.get_default_project().project_key 
endpoint = "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 response 
    for 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
Level 1
Author

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
Dataiker Alumni

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

Looking for more resources to help you use Dataiku effectively and upskill your knowledge? Check out these great resources: Dataiku Academy | Documentation | Knowledge Base

A reply answered your question? Mark as ‘Accepted Solution’ to help others like you!
0 Kudos
SarinaS
Dataiker

Hi @jurriaann,

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

Sarina 

0 Kudos

Labels

?
Labels (3)
A banner prompting to get Dataiku