Async Runs
Run Tasks asynchronously
Reason to use
For Tasks that you wish to run multiple times, the Async API is a great way to improve latency. Asynchronous operations allow multiple runs to be executed simulataneously, rather than sequentially. This means that while one execution is waiting to be completed, other runs can continue to execute. This can significantly improve your experience while using the Task API for large datasets.
The Task API supports polling and callback for individual Runs.
Process
Here is a step-by-step guide on how to use the Async Runs feature:
- First create a Task as you typically would.
- Post request with an extra argument
enqueue_run
set totrue
to the Task API.
- Poll the Run API to check the status of the Run. Once the run is complete, you can retrieve the results. More information on polling and callbacks can be found below.
Polling
To access the newly created Run, you can poll the Run API. Send a GET request:
Below are the possible statuses for a Run:
queued
: The run has been queued and is waiting to be processed.running
: The run is currently being processed.awaiting_tool_calls
: The run is waiting for tool calls to complete.complete
: The run has completed.failed
: The run has failed.cancelling
: cancellation requested; may still be runningcancelled
: The run has been cancelled.
Callback
To add a callback, use the callback_webhook
argument in the Task API.
We will send a post request to the URL provided once the run completes.
Note on Secrets
Secret is an optional field that can be used as an additional layer of security to check if the webhook call is coming from Parallel.
To verify that the message is correct and from us, you can do the equivalent of the following python code on the webhook server:
Note on headers
The headers are an optional field that can be used for authorizing parallel on the webhook server. For example, if your webhook server uses JWT, you can pass in the JWT token as a part of the headers into the callback webhook. Parallel will call the webhook server with these headers.