A run is a single execution of an app against an instance. It is the basic functionality encompassed of receiving an input, running the app, and returning an output. This tutorial will walk you through running an app remotely on Nextmv Cloud. It works the same for both subscription apps and custom apps.
There are several interfaces for running an app:
- Nextmv CLI: use your terminal.
- Python SDK: use Python.
- Cloud API: use the HTTP endpoints.
- Console: use the web interface.
The Nextmv CLI and Python SDK handle the complete run workflow: large payloads, polling, retries, status checking, timeouts, exponential backoff, and more for you.
There are two recommended methods for running an app:
When a new run is submitted, you can attach it to an existing batch experiment using the batch_experiment_id
field. This will ignore existing online experiments attached to the instance (shadow and switchback tests).
You can work with non-json input/output when executing remote runs to your app.
There is a size limit of 5MB when directly submitting/retrieving the input/output with the API endpoints. Larger payloads must use the large file method.
Polling
The polling method is the most common way to check the status of a run. It involves the following steps:
Submit a run request with the input (payload) and options (if desired). A
run_id
is returned.Sleep for an appropriate amount of time.
Get the
run_status_v2
in the metadata using therun_id
. The following states indicate that you should stop polling:succeeded
: the run completed and you can retrieve the run results.failed
: the run did not complete and you can retrieve the run error.canceled
: the run was canceled.
On the other hand, the following states indicate that you should continue polling:
Each time you check for the run status (poll), you should increase the time between polls. This is called exponential backoff. In addition, you should set a maximum number of retries and a timeout.
Once you are done polling, retrieve the run results or error using the
run_id
.
Cancel a run
You can cancel a run when it is no longer necessary. To cancel a run, you need the run_id
. Runs that are in the following states (given by run_status_v2
in the metadata) can be canceled:
You can cancel a run using the following methods:
Nextmv CLI. Use the
nextmv app cancel
command.Python SDK. Use the
Application.cancel_run
method.Cloud API. Use the following endpoint.
PATCHhttps://api.cloud.nextmv.io/v1/applications/{application_id}/runs/{run_id}/cancelCancel a run that is not yet completed.
Cancel a run that is not yet completed.
Queued runs
When you submit a run, it is placed in a queue. The run will be executed when resources are available. The queue is set at the account level, so you can visualize runs from all applications in the same queue. A run is queued when the status_v2
in the metadata is queued
.
To get the account queue you can use the following methods:
Nextmv CLI. Use the
nextmv account queue
command.Python SDK. Use the
Account.queue
method.Cloud API. Use the following endpoint.
GEThttps://api.cloud.nextmv.io/v1/account/queueList queued and active runs.
Retrieves a list of queued and active runs.