Skip to main content

Use the Stax API to Monitor Task Status

The Python SDK is the easiest way to get started with the Stax API. The Tasks components of the SDK and API allow monitoring of API operations in progress.

Before You Begin

Monitoring a Task's Status

A short Python script allows you to monitor the status of a Stax Task.

get-task.py

get-task.py below returns the context of a task including its status and any relevant logs/messages.

import json
import os
from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = os.getenv("STAX_ACCESS_KEY")
Config.secret_key = os.getenv("STAX_SECRET_KEY")
tasksClient = StaxClient("tasks")
task = tasksClient.ReadTask(task_id=os.getenv("TASK_ID"))

print(f"Task status: {task['Status']}")

if task['Logs']:
print("Logs:")
print(json.dumps(task['Logs']))

Invoke the script with your own API access key and secret key, as well as the Task ID you wish to query, as follows:

$ STAX_ACCESS_KEY=myaccesskey STAX_SECRET_KEY=mysecretkey TASK_ID=7e138167-fd8a-4206-b6f6-c71fc6ae9909 python get-task.py

A response similar to the below will be returned:

Task status: SUCCEEDED

For more examples of using the Stax Python SDK, see the examples.