The following is the general method to schedule apps.
This is possible by adding the following files to your project, app.py and requirements.txt. The method leverages a function in Domino's Python API call app_publish().
There is a written a script which takes advantage of this. To do so, simply:
- Upload app.py and requirements.txt(described below) into your project files.
- Create a scheduled job with the following command:
- Then, schedule this to run whenever you'd like your app to republish.
- Note, there will be a few minutes between the old instance shutting down and the new instance spinning up.
Additionally, if you'd like the app to shut down regularly, you can schedule a job using the command "app.py off"
Here are the two files you will need.
FILE 1: app.py -- for Domino versions between 4.4.0 ~ 4.6.x
import domino
import os
import sys
print("Domino python-wrapper version:", domino.__version__)
print("Minimum required python-wrapper version is 1.0.6")
from domino import Domino
action = sys.argv[1]
# Schedules may fail after a while unless this is set:
### unsetenv is not correct, it does not correctly demote the ENV!
### Replacing with pop: os.unsetenv('DOMINO_TOKEN_FILE')
os.environ.pop('DOMINO_TOKEN_FILE')
domino = Domino(os.environ['DOMINO_PROJECT_OWNER'] + "/" + os.environ['DOMINO_PROJECT_NAME'])
domino.authenticate(api_key=os.getenv("DOMINO_USER_API_KEY"))
if action == "on":
domino.app_publish()
print("publishing app")
elif action == "off":
domino.app_unpublish()
print("unpublishing app")
else:
raise ValueError('This script uses the format: app.py [on]/[off]')
FILE1: app.py -- for Domino versions between 4.0 ~ 4.3.0
from domino import Domino
import os
import sys
action = sys.argv[1]
# Schedules may fail after a while unless this is set:
os.unsetenv('DOMINO_TOKEN_FILE')
domino = Domino(os.environ['DOMINO_PROJECT_OWNER'] + "/" + os.environ['DOMINO_PROJECT_NAME'],
api_key=os.environ['DOMINO_USER_API_KEY'],
host=os.environ['DOMINO_API_HOST'])
if action == "on":
domino.app_publish()
elif action == "off":
domino.app_unpublish()
else:
raise ValueError('This script uses the format: app.py [on]/[off]')
FILE2: requirements.txt for all Domino versions 4.0+
dominodatalab
Note: You can also add the python-domino package installation to your Compute Environment Dockerfile Instructions instead of a requirements.txt file.
On older versions of Domino (e.g. 2.x, 3.x), you may see an error when using the latest version the python-domino package. If this occurs, you can install the 0.3.5 version of the python-domino package as follows:
pip install https://github.com/dominodatalab/python-domino/archive/0.3.5.zip
It's important to note that this works for all R/Shiny apps as well as Dash apps. The app.sh file in your projects determines what app gets published. This script, written in python, just calls an API to publish your app, so it is agnostic to the type of app you are publishing.
Comments
3 comments
Important to note that this works for all R/Shiny apps as well as Dash apps. The app.sh file in your projects determines what app gets published. This script, written in python, just calls an API to publish your app, so it is agnostic to the type of app you are publishing.
Submitted by: katie.shakman
For some users, especially if you do not log in on a regular basis, you may need to add this code to line 7 or 8:
The above token does expire and may have a higher priority than the API key. This can cause the task to fail if you have not logged into Domino recently.
When will Domino add this as a feature instead of requiring end users to maintain their own project files? Would prefer updates get automatically pushed, instead of getting failure notifications from legacy code.
Don't get me wrong though, this script is awesome and business critical. Kudos Daniel!
Please sign in to leave a comment.