Valohai has a list of default status for executions, such as queued, started, completed or error. In some cases you might want to set a custom status to a running execution, e.g. “Finished loading data” or “Running the last epoch”.
The default execution statuses are created, queued, started, completed, error, stopping, stopping (hard), and stopped.
You can set a custom status in your code by either using valohai-utils or an API call. The status will be visible in the execution details view and you can also access it via an API call if you want to pass it to for example some other service.
Set a custom status
You can set a custom status in your code by either using valohai-utils or an API call. The status will be visible in the execution details view and you can also access it via an API call if you want to pass it to for example some other service.
Setting the status with valohai-utils
The Python helper tool valohai-utils has a command that allows you to set the status. Remember to add it to your requirements.txt or pip install it at the beginning of your execution!
import valohai
valohai.set_status_detail("I'm working on it...")
Set status without valohai-utils
If you don’t want to use valohai-utils, it is possible to set the status with an API call. Below is a Python example that uses the requests package. If you are using some other language and would need help, contact the Valohai support.
import json
import requests
with open('/valohai/config/api.json', 'r') as json_file:
data = json.load(json_file)
headers = data["set_status_detail"]["headers"]
r = requests.post(data["set_status_detail"]["url"], headers=headers, json={"status_detail": "I'm working on it..."})
print(r.status_code)
Retrieve Status with REST API
You can see the status that you have set under the Details page for your execution. In addition, you can access it with the ExecutionRetrieve API endpoint from your local machine or from some external service, for example. This can be done even while the execution is still running.
Note that you will need an API token for this. Make sure to keep the token secret and to not include it in your version control as it can be used to access your Valohai account.
import requests
import json
import os
# Authenticate yourself with the token
auth_token = os.environ['VH_API_TOKEN']
headers = {'Authorization': 'Token %s' % auth_token}
# Send a GET request to the endpoint
url = 'https://app.valohai.com/api/v0/executions/{execution_id}/'
resp = requests.get(url, headers=headers)
# Print the status detail
print(resp.json()["status_detail"])